View Full Version : QString problem?
askbapi
31st March 2010, 12:24
QString userentry = ui->lineEdit->text();.
Now i need to loop through each character of the string and find the a matching charecter "A"
for(i=0;i<=20;i++)
{
if( userentry[i] == 'A' )
.............
}
I am getting error
Lykurg
31st March 2010, 12:38
What error do you get? use userentry.length() instead of fixed integer. See also QString::indexOf().
askbapi
31st March 2010, 14:34
how can I get each character of Qsrting?
Native C++ style:
---------------------------------------------------
char userenter[30]; int i;
userenter[]="god is great";
for(i=0; i<= 29; i++)
{
cout << userenter[i] << endl;
}
how to do it with QString?
Lykurg
31st March 2010, 15:09
QString str = "fooBar";
for (int i = 0; i < str.length(); ++i)
qWarning() << str.at(i); // or str[i]
aamer4yu
31st March 2010, 16:32
You can also use QString::indexOf , cant you :rolleyes:
wysota
31st March 2010, 17:03
Native C++ style:
---------------------------------------------------
char userenter[30]; int i;
userenter[]="god is great";
for(i=0; i<= 29; i++)
{
cout << userenter[i] << endl;
}
how to do it with QString?
QString userenter;
userenter ="god is great";
for(int i=0; i<= userenter.size(); i++)
{
cout << userenter[i] << endl;
}
By the way, your code is incorrect.
askbapi
31st March 2010, 18:03
Thanks for your valuable reply! :)
It is clear.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.