New topic: 

Parsing CSV Comma delimited file - query

<http://forums.realsoftware.com/viewtopic.php?t=33852>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        imagoworld          Post subject: Parsing CSV Comma delimited 
file - queryPosted: Tue May 18, 2010 11:10 pm                         
Joined: Mon Jan 04, 2010 3:43 pm
Posts: 4                Hello,

I would like to process CSV files and I'm not sure of the best way for 
splitting text lines into fields. 

For example :

field 1,field 2,"field 3 : product description with a comma,","field 4 : with 
double ""quotes"" here"

Which function can be used to split the above line using the comma as a 
delimiter?

The result should be 4 fields, using the Split function would create 5 fields. 
Are there any other functions that I can try?

Thank you,

imagoscape   
                             Top                 DaveS          Post subject: 
Re: Parsing CSV Comma delimited file - queryPosted: Tue May 18, 2010 11:14 pm   
                              
Joined: Sun Aug 05, 2007 10:46 am
Posts: 2355
Location: San Diego, CA                Code:dim v(-1) as string
v=split(yourdata,",")


opps... should read the OP better next time      
_________________
Dave Sisemore
MacPro, OSX 10.6.2 RB2009r5.1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                denisc          Post subject: 
Re: Parsing CSV Comma delimited file - queryPosted: Tue May 18, 2010 11:55 pm   
                      
Joined: Wed Mar 17, 2010 10:33 am
Posts: 31                Had the same problem a while ago.

Doesn't seem to matter what you use as a delimiter some twit will use it in a 
description.
Even the '~' isn't safe... 

For me the file was produced by a unix server so without a lot of effort the 
number of fields I 'should' have was static.

I haven't got the code available, it's at the clients, but I did something 
like....

Code:dim sNewDelimiter As String = ":~::"
redim the array
split the line

if the number of fields IS NOT what I'm expecting

redim sNewLine(-1)
loop i = 1 to line.length
  // if it's a comma but NOT within a 'text' field
  if char = comma and bTextMode = False then
  sNewLine.Append sNewDelimiter
  Else
  sNewLine.Append char
  End If

  // if it's a double quote
  If char = double quote then
  // and text mode is on, must be the end of the text, turn it off
  If bTextMode then 
  bTextMode = False
  // must be the start of the text
  Else
  bTextMode = True
  End If
  End If
end loop

redim the array
array = split(join(sNewLine,""), sNewDelimiter)



Hmmm, I think that's it, but me memory ain't what it used to be.. 

Hope it Helps

Regards
Denis   
                             Top                imagoworld          Post 
subject: Re: Parsing CSV Comma delimited file - queryPosted: Wed May 19, 2010 
1:37 am                         
Joined: Mon Jan 04, 2010 3:43 pm
Posts: 4                Hi Denis,

Thank you for the info, I'll try your code.

cheers,

imagoscape   
                             Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to