Re: smart split ?



At 2007-06-01 03:46PM, "sasi" wrote:
Hi,
i am looking for some solution to split a string.
my string looks like this
"Name, last", "Name, first", 123, "12/05/2007", " comments,test this",
someotherstring

i need to split it like
{Name, last} {Name, first} { 123} {12/05/2007} {comments,test
this} {someotherstring}

the problem is, i want to split it with comma (,)
but should ignore the comma with quotes

tcllib to the rescue:

% set line {"Name, last", "Name, first", 123, "12/05/2007", " comments,test this", someotherstring}
"Name, last", "Name, first", 123, "12/05/2007", " comments,test this", someotherstring
% package req csv
0.6
% set lst [csv::split $line]
{Name, last} { Name, first} { 123} { 12/05/2007} { comments,test this} { someotherstring}

I notice most of the output fields have leading spaces, so you could
string trim the results if required.

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
.



Relevant Pages

  • Re: Compiler optimization, which one is faster? or are they even?
    ... Listing 1: ... if (TheThing.StringProperty == SomeOtherString) ... SortedList<int, string> MyThingsStringProperty; ...
    (microsoft.public.dotnet.framework.performance)
  • Re: smart split ?
    ... sasi wrote: ... i am looking for some solution to split a string. ... this} {someotherstring} ... the problem is, i want to split it with comma ...
    (comp.lang.tcl)
  • smart split ?
    ... i am looking for some solution to split a string. ... this} {someotherstring} ... the problem is, i want to split it with comma ... but should ignore the comma with quotes ...
    (comp.lang.tcl)
  • Re: a regex that does not contain comma
    ... string = "Hello, world" ... puts "string does not contain a comma" ... Glenn Jackman ...
    (comp.lang.ruby)
  • Re: CDBL Function truncates decimals
    ... Public Function ConvertNumberforSQL (ByVal sValue As String, ... vlDefaultNumber As Double= 0) as Double ... Since the Spanish formatting has a comma, the SQL statement seems to have ...
    (microsoft.public.vb.general.discussion)