Click to See Complete Forum and Search --> : ASCII value from CString?


chamo
April 19th, 1999, 10:44 AM
Hi all,
I need to know the ASCII value of a string.
I am using a CString object.
With the GetAt() method, I do not have the right value for the french special char (é(130), ê(136), è(138)). I get an negativ values.
Can any body help me?

ValerieB
April 19th, 1999, 11:40 AM
You need to use a function that understands Unicode and/or wide-char sets. Look at header tchar.h, it includes routines that map to either single-char, wide-char, or unicode functions as necessary.

For you, I'd suggest the following:

#include <tchar.h>
...
CString szNumberString = "124";
int iNumber = _ttoi((LPTSTR)szNumberString);

The function _ttoi() is mapped to one of the following functions, depending on how it was compiled:
atoi() if _UNICODE & _MBCS Not Defined
atoi() if _MBCS Defined
_wtoi() if _UNICODE Defined

There are actually a lot of functions like this that are very handy if you're writing programs that don't use the standard character set.

I hope this will point you in the right direction. Good luck, and happy coding!

Valerie Bradley
http://www.synthcom.com/~val
val@synthcom.com

sally
April 19th, 1999, 07:29 PM
cast it to an UINT and you'll get the correct value

Sally

Sally
April 19th, 1999, 07:29 PM
cast it to an UINT and you'll get the correct value

Sally

chamo
April 20th, 1999, 01:53 AM
Hi, it's me (again)
Thanks for your answer ValerieB.
But it doesn't the expected result.

CString szNumberString = "124";
int iNumber = _ttoi((LPTSTR)szNumberString);



With this code I always got an 0 with special char ('é', 'ê').
Have you an another idea?

chamo
April 20th, 1999, 08:45 AM
Hi all!
Again my question!
if I define CString like
CString s("éh");
Is it possible to get the ASCII value of the first char (é : 130), as describe in the "ASCII Character Codes Chart 2"?

Or it is only possible to have the unicode value : 0xE9?
Thanks in advance

Gary Grant
April 20th, 1999, 09:33 AM
The default behavior for a char is signed. This will cause any character with an ASCII value greater
than 127 to have a negative number. Try adding a /J switch to your compiler options.
This will change the default for char to unsigned.