ASCii value of a CString object
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: ASCii value of a CString object

  1. #1
    Join Date
    Jul 2005
    Posts
    85

    Question 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

  2. #2
    Join Date
    Aug 2005
    Posts
    115

    Re: ASCii value of a CString object

    You can use either the GetAt() function or the subscript [] operator. Here's more info on CString.

  3. #3
    Join Date
    Sep 2005
    Posts
    22

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center