-
September 5th, 2005, 09:27 PM
#1
ASCii value of a CString object
Hi
can someone pls tell me, in mfc, how do I obtain the ascii value of a CString object
eg
CString cs ="Ac20"
how do I get the ascii value of each char in the string?
Thanks
-
September 5th, 2005, 09:33 PM
#2
Re: ASCii value of a CString object
You can use either the GetAt() function or the subscript [] operator. Here's more info on CString.
-
September 5th, 2005, 09:40 PM
#3
Re: ASCii value of a CString object
You can simple assign the char to a int variable
You can display the hex value as well using %x in a string
Code:
CString szString = "Ac20";
int nValue;
nValue = szString[0]; // nValue will store a value of 65, which is the ASCII value for 'A'
CString szMsg;
szMsg.Format("%d %02x", b, b); // szMsg will appear as "65 41"
Hope this helps.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|