Fwd: Re: Problem in splitting a string

paolo veronelli paolo_veronelli at yahoo.it
Thu Jul 22 23:47:59 CEST 2004



------- Forwarded message -------
From: paolo veronelli <paolo_veronelli at yahoo.it>
To: Angelo Secchi <secchi at sssup.it>
Subject: Re: Problem in splitting a string
Date: Thu, 22 Jul 2004 23:40:04 +0200

> On Thu, 22 Jul 2004 20:16:32 +0200, Angelo Secchi <secchi at sssup.it> 
> 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.
>>
>> How can I do that?
>
>
> I don't know if it works but with:
>
> def _split(stringa,splitter,escaper):
> 	escapingCount=0
> 	piece=''
> 	ret=[]
> 	for c in stringa:
> 		if c==splitter and not escapingCount%2:
> 			ret.append(piece)
> 			piece=''
> 		else:
> 			if c==escaper:
> 				escapingCount+=1
> 			piece+=c
> 	ret.append(piece)
> 	return ret
>
> _split(',,,,,,23,,,asd,,,,,"name,surname",,,,,,,\n',',','"')
>
> you have something to refine
>
> 						regards Paolino



-- 
....lotta dura  per la verdura




More information about the Python-list mailing list