Convert string to char array
Larry Bates
larry.bates at websafe.com`
Tue Jul 1 14:57:16 EDT 2008
Brandon wrote:
> How do I convert a string to a char array? I am doing this so I can edit
> the string received from an sql query so I can remove unnecessary
> characters.
>
>
The precise answer is:
>>> s = 'abcdefghi'
>>> l = list(s)
>>> l
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
>>>
But quite often you can just to the replace without doing the conversion
>>> s = 'abc,de,fghi'
>>> s2 = s.replace(',','')
>>> s2 = s.replace(',','')
'abcdefghi'
>>>
-Larry
More information about the Python-list
mailing list