CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 1999
    Location
    europe/ch
    Posts
    22

    ASCII value from CString?

    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?


  2. #2
    Join Date
    Apr 1999
    Location
    Portland, OR, USA
    Posts
    18

    Re: ASCII value from CString?

    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]

  3. #3
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: ASCII value from CString?

    cast it to an UINT and you'll get the correct value

    Sally


  4. #4
    Join Date
    Apr 1999
    Location
    europe/ch
    Posts
    22

    Re: ASCII value from CString?

    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?



  5. #5
    Join Date
    Apr 1999
    Location
    europe/ch
    Posts
    22

    Re: ASCII value from CString?

    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



  6. #6
    Join Date
    Apr 1999
    Location
    Michigan, USA
    Posts
    115

    Re: ASCII value from CString?

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured