Results 1 to 3 of 3

Thread: ASCII to int and int to ASCII

  1. #1
    Join Date
    Mar 2010
    Location
    Alipurduar, India
    Posts
    8
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default ASCII to int and int to ASCII

    How cam I get ASCII value (int) of each character of "QString" and again change it back into Characters ?

    Native code - ASCII value of character
    -----------------------------------
    char str[21];
    str[]="Good boy";
    for(i=0;i<=20;i++)
    {
    cout << int(str[i]);

    }

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: ASCII to int and int to ASCII

    Quote Originally Posted by askbapi View Post
    char str[21];
    str[]="Good boy";
    for(i=0;i<=20;i++)
    {
    cout << int(str[i]);

    }
    Did you lear anything from your last post??? And please use the documentation of QString. All answers can be found there: QChar::unicode().

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: ASCII to int and int to ASCII

    ... but since you don't use Qt in your example, simply use C++:
    Qt Code:
    1. int x = (int) str[0] - '0';
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QKeyEvent - no ASCII characters
    By ctarsoaga in forum Qt Programming
    Replies: 6
    Last Post: 17th February 2010, 10:34
  2. ASCII to PDF
    By jaca in forum Newbie
    Replies: 3
    Last Post: 19th September 2009, 23:51
  3. get ASCII equivalent data
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2009, 04:13
  4. Ascii problem
    By eekhoorn12 in forum Qt Programming
    Replies: 5
    Last Post: 17th October 2007, 13:59
  5. Howq to get the ascii of a char ?
    By yellowmat in forum Newbie
    Replies: 2
    Last Post: 27th April 2006, 21:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.