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?
Printable View
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?
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
[email protected]
cast it to an UINT and you'll get the correct value
Sally
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?
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
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.