PDA

View Full Version : How to Compare Characters ASCII value?



merry
14th July 2008, 06:31
Hi all

working on Qt4.3, I want to know how to compare Character Ascii values .

For eg.

QString str;

how can i get that, Is str contains Character Ascii values between [0-31], if str contains the value between [0-31], then also how can i remove that ASCII value lies between [0-31].

munna
14th July 2008, 07:11
use toAscii (http://doc.trolltech.com/4.4/qstring.html#toAscii) to get 8-bit ASCII representation of the string

merry
14th July 2008, 07:21
Thanks 4 d reply, It returns an 8-bit ASCII representation of the string,
but how can i compare this , that the ASCII values is between [0-31] or not.

Pls explain it with me example

aamer4yu
14th July 2008, 07:28
You may very well write ur own function for that -


void removeDirtyChars(QString &input)
{
QByteArray asciiInput = input.toAscii();
input.clear();
for(int i=0;i<asciiInput.length();i++)
{
if(asciiInput.at(i) is not between [0-31] // You logic to determine which chars u want
input += asciiInput.at(i);
}
}

Hope u get the logic

merry
14th July 2008, 07:42
Thanks for d reply, I got the logic, but there is a confusion in a line


if(asciiInput.at(i) is not between [0-31] You logic to determine which chars u want

I want to compare all the characters whose ASCII value lies between [0-31], how can i do this, Is I have to compare ASCII value one by one or is there any other logic

merry
14th July 2008, 12:05
Thanks all my problem is solved.