473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 59459
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Trep | last post by:
Hi there! I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003. This is necessary because I...
16
by: Dave | last post by:
Hi all, I have a 4 byte char array with the binary data for two 16-bit signed integers in it like this: Index 3 2 1 0 Data Bh Bl Ah Al Where Bh is the high byte of signed 16-bit...
13
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. ...
0
by: joye | last post by:
Hello , I meet some data convertion problem, the sample code as following, namespace Configure { using namespace System ; typedef struct _SW{ char szVersion ;
1
by: joye | last post by:
Hello , I meet some data convertion problem, the sample code as following, namespace Configure { using namespace System ; typedef struct _SW{ char szVersion ;
3
by: David | last post by:
Hi, how to convert a char array(byte) to a string variable? byte buffer; string strTest; /*the blow codes all get type of 'buffer': System.Byte! strTest = buffer.ToString() strTest =...
1
by: mangala | last post by:
i hav gotta convert an int array to a char array.. so that i can write it to the socket.. that is in the server side.. n in the client side i gotta read d socket... get d char array n convert it...
0
by: =?utf-8?q?C=C3=A9dric_Lucantis?= | last post by:
Le Thursday 19 June 2008 17:12:08 Jonno, vous avez écrit : string = '0.906366 2.276152 0.013369 80.773141' array = -- Cédric Lucantis
2
by: lakshmiRam | last post by:
i am working on a application where i will get data as char now to the caller i need to send it as jbytearray, is it possible if so how plz give me a ex to show this...
2
by: Frnk Carleo | last post by:
I am looking to convert a char array defined as char pstrInputClaim to a std::wstring trying to use the constructor as below std::wstring strInputClaim(pstrInputClaim);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.