469,317 Members | 1,833 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,317 developers. It's quick & easy.

Convert string to char array

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.
Jul 1 '08 #1
3 58764
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
Jul 1 '08 #2
On Jul 1, 2:49*pm, "Brandon" <deanfamil...@verizon.netwrote:
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.
Answering your specific question:

Python 2.5.1 (r251:54863, Mar 31 2008, 11:09:52)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>s = 'hello'
l = list(s)
l
['h', 'e', 'l', 'l', 'o']
>>>
But more generally, you might want to read up on the string methods
available to you, such as replace():
http://docs.python.org/lib/string-methods.html
Jul 1 '08 #3
Thank you both for your help.

"Mike Kent" <mr******@cox.netwrote in message
news:46**********************************@r66g2000 hsg.googlegroups.com...
On Jul 1, 2:49 pm, "Brandon" <deanfamil...@verizon.netwrote:
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.
Answering your specific question:

Python 2.5.1 (r251:54863, Mar 31 2008, 11:09:52)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>s = 'hello'
l = list(s)
l
['h', 'e', 'l', 'l', 'o']
>>>
But more generally, you might want to read up on the string methods
available to you, such as replace():
http://docs.python.org/lib/string-methods.html
Jul 1 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by =?utf-8?q?C=C3=A9dric_Lucantis?= | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.