Re: Problem in splitting a string

From: Jeff Shannon (jeff_at_ccvcorp.com)
Date: 07/22/04


Date: Thu, 22 Jul 2004 12:11:04 -0700

Angelo Secchi wrote:

>Hi,
>I have string of numbers and words like
>
>',,,,,,23,,,asd,,,,,"name,surname",,,,,,,\n'
>
>and I would like to split (I'm using string.split()) it using comma as
>separator but I do not want to split in two also the "name,surname"
>field. In other word I would like python in separating fields to skip
>that particular comma.
>
>

You may be able to use regular expressions (the re module) to hack
something together that'll work for your particular case. In the
general case, though, splitting delimiter-separated values in the
presence of quoting and escaping is a nontrivial problem.

I remember some discussion, quite a while ago, about several people
working on a DSV module that would handle all of this stuff, but I don't
know what became of that.

Jeff Shannon
Technician/Programmer
Credit International



Relevant Pages

  • Re: Problem in splitting a string
    ... Angelo Secchi wrote: ... > that particular comma. ... You may want to look at regular expressions, but in the example you gave, ... you just have to split the string at the quotation marks, ...
    (comp.lang.python)
  • Re: Problem in splitting a string
    ... Angelo Secchi wrote: ... > I have string of numbers and words like ... In other word I would like python in separating fields to skip ... > that particular comma. ...
    (comp.lang.python)
  • 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)
  • Re: .join() !== + a + b; // for some a and b
    ... convert that final value into a string to be used as the name of the ... 8), 9 -, so two comma operations. ... bracket notation property accessor, which converts it into a string ... interpreted as simply zero for the purpose of the echo. ...
    (comp.lang.javascript)
  • Re: Finding multiple occurrences of character in word document
    ... the text into a string, and do a Split with the comma as a delimiter. ... For Each rngSentence In ActiveDocument.Sentences ... highlight the two positions. ...
    (microsoft.public.word.vba.general)