|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Minimize the cost of deploying database applications. Advantage Database Server or Microsoft SQL Server – Which One is Right for You? Learn now! |
|
#1
|
|||
|
|||
|
Convert CString to ASCII values
In VC++ 6, I need to convert each character in a CString to their ASCII values. What function(s) should I use?
Any help is appreciated. Thanks. |
|
#2
|
||||
|
||||
|
Re: Convert CString to ASCII values
Sounds like you're compiling with support for UNICODE strings. In that case, you use wctomb().
__________________
Jon Sagara "Me fail English? That's unpossible!" |
|
#3
|
|||
|
|||
|
First of all, thanks for the quick response, Jon.
Actually I'm not doing anything related to UNICODE. The purpose of my function is to convert every single character in a CString to its ASCII value. For example: "abc.com" -> 97 98 99 46 99 111 109 I need the numerical ASCII values, so I dun think wctomb would work in my case. Do you have any other suggestions? Thanks. |
|
#4
|
||||
|
||||
|
Hmm...
Well, I suppose you can get the buffer (CString::GetBuffer()) and then assign the characters to an int. A char is really an int (short), so the types are interchangeable. Ex: char mychar = 'a'; printf("char: %c\n", mychar); // Prints the character 'a' printf("ASCII: %d\n", mychar); // Prints the number 97 That's the only way I can think of to do get the ASCII value. |
|
#5
|
|||
|
|||
|
Thanks again.
I want to convert characters in name to ASCII, then append this to name2. eg. name = "abc", name2="test"; then after the operation, i need "test878889". Here is what I've got so far CString name, name2; char *ptr; int length = name.GetLength(); int i; ptr = name.GetBufferSetLength(length); for (i=0; i<length; i++, ptr++) { name += (short)(*ptr); } but of course it's not turning out right. I get "testabc" instead of what i needed. what do you do to (*ptr) to get it's numerical value? Thanks a lot for your help! |
|
#6
|
|||
|
|||
|
Just adding...
you can easily assign the ascii value to an integer variable.... int i; char c='A'; i=c; // i is now 65. |
|
#7
|
|||
|
|||
|
Ok the problem is that I'm not converting interger to CString correctly. I used _itoa() and it worked.
Thanks for all your help. ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Convert CString to ASCII values |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|