CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005

    Question ASCii value of a CString object

    can someone pls tell me, in mfc, how do I obtain the ascii value of a CString object


    CString cs ="Ac20"

    how do I get the ascii value of each char in the string?


  2. #2
    Join Date
    Aug 2005

    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

    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

    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

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.