It is currently Thu May 25, 2017 5:37 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Delimiter convention?
Unread postPosted: Fri Dec 02, 2016 4:26 pm 
Offline

Joined: Sat Nov 26, 2016 4:23 pm
Posts: 11
The function Split.all seems to be ignoring a basic convention of CSV formatting?
My text.readln command reads a csv header row thus:-
Number,Scheme,Location,Date,Category,"L-Lost, R-Repaired, D-Discarded",Serviced

When I then use Split.all with the comma delimiter and print I get:-
Number
Scheme
Location
Category
"L-Lost
R-Repaired
D-Discarded"
Serviced


The convention of processing values between delimiters is to treat a value enclosed in quotes ("...") as an entire value.
Is there a way to use the regular-expression facility of the delimiter parameter to get:-

Number
Scheme
Location
Category
L-Lost, R-Repaired, D-Discarded
Serviced



Thanks
chrisRoald


Last edited by chrisRoald on Sat Dec 03, 2016 4:36 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Delimiter convention?
Unread postPosted: Fri Dec 02, 2016 11:38 pm 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
Hi Chris,

Nowhere in the manual is it written that Split.All follows the CSV convention.

On the contrary, it is explicitly written
De Re BASIC! wrote:
The string is split at each location where <test_sexp> occurs.


It is also written
De Re BASIC! wrote:
Note: The <test_sexp> is actually a Regular Expression. If you are not getting the results that you expect from the <test_sexp> then you should examine the rules for Regular Expressions at:

http://developer.android.com/reference/ ... ttern.html


Now that we referred to the manual, and that it nicely gave us the advice we were waiting for since we're in the exact situation it describes, let's do a Google search on
google.com wrote:
java regex split comma except in quotes


The first result is this link: http://stackoverflow.com/questions/1757065/java-splitting-a-comma-separated-string-but-ignoring-commas-in-quotes

The first answer gives us the answer (yes I know, it's a very complicated answer but so are regexes):
Code:
mystring$="Number,Scheme,Location,Date,Category,\"L-Lost, R-Repaired, D-Discarded\",Serviced"
regex$=",(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)"
Split.All result$[], mystring$, regex$


Nicolas

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: Delimiter convention?
Unread postPosted: Sat Dec 03, 2016 12:27 pm 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
first, split at ", then split at "," if ends or starts with ","


Top
 Profile  
 
 Post subject: Re: Delimiter convention?
Unread postPosted: Sat Dec 03, 2016 12:51 pm 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 656
Location: UK
gikam wrote:
first, split at ", then split at "," if ends or starts with ","

It may be tricky to verify which parts of text are "inside" and "outside" the '""... (Alternate portions?)

Mike.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred