Results 1 to 7 of 7

Thread: How to become int from code ASCII nummer?

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to become int from code ASCII nummer?

    How to become int code ASCII nummer?

    QString onechar= "4"; /* not int */
    asci code nummer ??

    php is int nummer = ord("4"); target http://php.net/ord

  2. #2
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to become int from code ASCII nummer?

    Quote Originally Posted by patrik08
    How to become int code ASCII nummer?

    QString onechar= "4"; /* not int */
    asci code nummer ??

    php is int nummer = ord("4"); target http://php.net/ord
    Instead of a string use a char (using single quotes), or get the single char as a char. Take it as an int. That is the code value.

    int asciiVal = '4';

    Note that if you want to get the numeric value of a numeric char, you can do it easily like this:

    int num = '4' - '0';

    And, going the other way:

    char value4 = '0' + 4;

    rickb

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to become int from code ASCII nummer?

    I can not set char if incomming is QString

    i wand only asci nummer from qtcharnummer to check and validate if nummer is ok...

    original ist so..... /*(ord(substr($str,$i,1))-48); original php code */


    search asci on assitant return NULL!


    ord

    (PHP 3, PHP 4, PHP 5)
    ord -- Return ASCII value of character
    Description
    int ord ( string string )

    Returns the ASCII value of the first character of string. This function complements chr().




    Qt Code:
    1. QString insertname = cognome->text();
    2. if (insertname.size() > 0) {
    3. QString first = TakeFirstNr(insertname);
    4. qDebug() << "### insertname " << insertname;
    5. qDebug() << "### first " << first;
    6. QString insurancenr =QString("%1%2%3%4").arg( first , QString::number(ahv_anno) , QString::number(base2) , QString::number(state) );
    7. /* check the first 10 nummer */
    8. for(int i=0; i<10; i++) {
    9. /*(ord(substr($str,$i,1))-48); original php code */
    10. QString qtcharnummer = insurancenr.mid(i,1);
    11. qDebug() << "### check and validate charx " << qtcharnummer << " " << i;
    12. }
    13. QString avsnummer =QString("%1.%2.%3.%4").arg( first , QString::number(ahv_anno) , QString::number(base2) , QString::number(state) );
    14. numeroavsai->setText(avsnummer);
    15. }
    To copy to clipboard, switch view to plain text mode 





    ASCI Table found on http://www.lookuptables.com/ -45 is number allowed or not to set the last sequenze....
    Last edited by patrik08; 2nd July 2006 at 19:34.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to become int from code ASCII nummer?

    QString::operator[] returns QChar which has an isDigit() method.

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to become int from code ASCII nummer?

    Asci code number => http://www.lookuptables.com/

    i solved so ... and the formula running
    int actualascivalue = direct_int(QString::number(insurancenr[i].toAscii(), 10));

    IMO this is a piece of formula to get the swisse insurance people number.. is a nummer unique of each women or men...

    Qt Code:
    1. int Gui_Main::direct_int(QString xid)
    2. {
    3. int newnummer = 0;
    4. if (is_numeric(xid)) {
    5. bool ok;
    6. newnummer = xid.toInt(&ok);
    7. return newnummer;
    8. }
    9. return newnummer;
    10. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. QString insertname = cognome->text(); /* get name of person */
    2. if (insertname.size() > 0) {
    3. QString first = TakeFirstNr(insertname);
    4. qDebug() << "### insertname " << insertname;
    5. qDebug() << "### first " << first;
    6. QString insurancenr =QString("%1%2%3%4").arg( first , QString::number(ahv_anno) , QString::number(base2) , QString::number(state) );
    7. /* check the first 10 nummer */
    8. QString checkers ="5,4,3,2,7,6,5,4,3,2";
    9. QStringList cheklist = checkers.split(",");
    10. int summs = 0;
    11. for(int i=0;i<10;i++){
    12. QString xs = insurancenr.mid(i,1);
    13. /*int basenrcheck = 0;*/
    14. int actualascivalue = direct_int(QString::number(insurancenr[i].toAscii(), 10));
    15. int comparation = direct_int(cheklist.at(i));
    16. summs += comparation * (actualascivalue - 48);
    17. qDebug() << "### summs " << summs;
    18. /*summs +=basenrcheck;*/
    19. /*qDebug() << "### checks nr=" << xs << " base=" << basenrcheck << " actualascivalue="
    20.   << actualascivalue << " comparation=" << comparation; */
    21. }
    22.  
    23. state +=(11-(summs%11)%10);
    24. qDebug() << "### summs " << state;
    25. QString avsnummer =QString("%1.%2.%3.%4").arg( first , QString::number(ahv_anno) , QString::number(base2) , QString::number(state) );
    26. numeroavsai->setText(avsnummer); /* swisse insurance number formula name birth state */
    27. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 3rd July 2006 at 00:54. Reason: code changed, so it doesn't break the page layout

  6. #6
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to become int from code ASCII nummer?

    Quote Originally Posted by jacek
    QString:perator[] returns QChar which has an isDigit() method.
    Right. But that just returns a boolean indicating whether it's a digit or not.

    Here's one way:

    Qt Code:
    1. QString aString("aString");
    2.  
    3. char *str = aString.ascii(); // returns a C-String
    4. int asciiVal = str[0]; // 0x61 - or just use str[0]
    To copy to clipboard, switch view to plain text mode 


    or:

    Qt Code:
    1. asciiVal = aString[0].latin1(); // 0x61
    To copy to clipboard, switch view to plain text mode 

    In the latter, an index operation on aString returns a QChar, which as a 'latin1' accessor to the latin1 value (latin1 & ascii the same on the first 128 index range).

    rickb

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to become int from code ASCII nummer?

    Quote Originally Posted by rickbsgu
    Right. But that just returns a boolean indicating whether it's a digit or not.
    Everything depend how one understands: "i wand only asci nummer from qtcharnummer to check and validate if nummer is ok...".

    And you can always use QChar::digitValue() to avoid conversions between encodings.

Similar Threads

  1. Howq to get the ascii of a char ?
    By yellowmat in forum Newbie
    Replies: 2
    Last Post: 27th April 2006, 21:05
  2. Code editor
    By Michiel in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2006, 17:20
  3. Mac Port of Windows code
    By Nemo in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2006, 07:37

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.