Re: Splitting comma-seperated items

Tech-Archive recommends: Fix windows errors by optimizing your registry



Regex is a great way to go. I would say that an alteration of the method, to change the commas not in the middle of quotes, so you could split, would be faster for what he is trying to do. :-)

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*********************************************
Think outside the box!
*********************************************
"Chris Taylor" <chris_taylor_za@xxxxxxxxxxx> wrote in message news:EF723234-16F7-4486-9936-EB60146C9B5E@xxxxxxxxxxxxxxxx
Hi,

You can try the following regular expression

Regex regex = new Regex("((?<field>[^\",\\r\\n]+)|\"(?<field>([^\"]|\"\")+)\")(,|(?<rowbreak>\\r\\n|\\n|$))");
foreach(Match match in regex.Matches(s))
{
Console.WriteLine(match.Value);
}

The result will include the comma and the quotes as follows

9006374,
7912103,
0,
"MICHEAL JACKSON, AAMC",
"102-3085146-8388914"

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


"MSNEWS" <someone@xxxxxxxxxxxxx> wrote in message news:%23pq5R8$gHHA.3412@xxxxxxxxxxxxxxxxxxxxxxx
Hi

i need to extract all items between commas into a string array from the following line, but there is a comma in one of the items (between strings) eg "MICHEAL JACKSON, AAMC" , i used String.Split() method but it fails.

9006374,7912103,0,"MICHEAL JACKSON, AAMC","102-3085146-8388914"

can anyone help out

TIA
Barry





.



Relevant Pages

  • Re: Hi - Regular Expression
    ... for general validation, it's ok. ... we can find that such regex won't ... validate the comma 's position(we can insert discretionary commas in any ... Microsoft Online Support ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: split : string containing brackets
    ... commas, but avoiding splitting where the comma is enclosed in some ... then you may count over the brackets ... The Regex is relatively ...
    (comp.lang.perl.misc)
  • Re: Email Validation for multiple emails (comma separated)
    ... Sorry for my bad english. ... I currently am using the following regex in js for email validation, ... in which the email addresses can be separated by commas or ... semicolons. ...
    (comp.lang.javascript)
  • help - regex validator expression not weeding out commas
    ... i am trying to validate a field for a double, but not allow commas ... and any number of digits after the decimal * ... as is i am having to use a range validator for double, ... but i would prefer the regex. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How do I include quotation marks in a TOC field code?
    ... As for the commas inside/outside the quotes, ... >>> you use italics, ... >>> Microsoft MVP ...
    (microsoft.public.word.docmanagement)