PDA

View Full Version : How to become int from code ASCII nummer?



patrik08
2nd July 2006, 15:06
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

rickbsgu
2nd July 2006, 15:26
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

patrik08
2nd July 2006, 20:26
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().






QString insertname = cognome->text();
if (insertname.size() > 0) {
QString first = TakeFirstNr(insertname);
qDebug() << "### insertname " << insertname;
qDebug() << "### first " << first;
QString insurancenr =QString("%1%2%3%4").arg( first , QString::number(ahv_anno) , QString::number(base2) , QString::number(state) );
/* check the first 10 nummer */
for(int i=0; i<10; i++) {
/*(ord(substr($str,$i,1))-48); original php code */
QString qtcharnummer = insurancenr.mid(i,1);
qDebug() << "### check and validate charx " << qtcharnummer << " " << i;
}
QString avsnummer =QString("%1.%2.%3.%4").arg( first , QString::number(ahv_anno) , QString::number(base2) , QString::number(state) );
numeroavsai->setText(avsnummer);
}







ASCI Table found on http://www.lookuptables.com/ -45 is number allowed or not to set the last sequenze....

jacek
2nd July 2006, 21:04
QString::operator[] returns QChar which has an isDigit() method.

patrik08
2nd July 2006, 21:41
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...



int Gui_Main::direct_int(QString xid)
{
int newnummer = 0;
if (is_numeric(xid)) {
bool ok;
newnummer = xid.toInt(&ok);
return newnummer;
}
return newnummer;
}




QString insertname = cognome->text(); /* get name of person */
if (insertname.size() > 0) {
QString first = TakeFirstNr(insertname);
qDebug() << "### insertname " << insertname;
qDebug() << "### first " << first;
QString insurancenr =QString("%1%2%3%4").arg( first , QString::number(ahv_anno) , QString::number(base2) , QString::number(state) );
/* check the first 10 nummer */
QString checkers ="5,4,3,2,7,6,5,4,3,2";
QStringList cheklist = checkers.split(",");
int summs = 0;
for(int i=0;i<10;i++){
QString xs = insurancenr.mid(i,1);
/*int basenrcheck = 0;*/
int actualascivalue = direct_int(QString::number(insurancenr[i].toAscii(), 10));
int comparation = direct_int(cheklist.at(i));
summs += comparation * (actualascivalue - 48);
qDebug() << "### summs " << summs;
/*summs +=basenrcheck;*/
/*qDebug() << "### checks nr=" << xs << " base=" << basenrcheck << " actualascivalue="
<< actualascivalue << " comparation=" << comparation; */
}

state +=(11-(summs%11)%10);
qDebug() << "### summs " << state;
QString avsnummer =QString("%1.%2.%3.%4").arg( first , QString::number(ahv_anno) , QString::number(base2) , QString::number(state) );
numeroavsai->setText(avsnummer); /* swisse insurance number formula name birth state */
}

rickbsgu
3rd July 2006, 01:41
QString::operator[] 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:



QString aString("aString");

char *str = aString.ascii(); // returns a C-String
int asciiVal = str[0]; // 0x61 - or just use str[0]



or:



asciiVal = aString[0].latin1(); // 0x61


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

jacek
3rd July 2006, 02:03
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.