0

How can I find out if a specific character in a QString is a letter or punctuation in any language?

For example I want to find the . in gâteau. but not the â.

Samuel Harmer
  • 4,264
  • 5
  • 33
  • 67
castors33
  • 477
  • 10
  • 26

2 Answers2

4

Try

str.at(i).isLetter()

It will return true for the unicode classes Letter_Uppercase/Lowercase/Titlecase/Modifier/Other. Which you can see here:

http://www.sql-und-xml.de/unicode-database/lu.html

http://www.sql-und-xml.de/unicode-database/ll.html

http://www.sql-und-xml.de/unicode-database/lt.html

http://www.sql-und-xml.de/unicode-database/lm.html

http://www.sql-und-xml.de/unicode-database/lo.html

DerManu
  • 702
  • 4
  • 12
2

You can get a QChar out of a QString using at(), and QChar has a isLetter() function. Thus, you want something like:

QString myString;
if (myString.at(3).isLetter()) {
   qDebug() << "letter number 4 in the string is a letter";
}
Wes Hardaker
  • 21,735
  • 2
  • 38
  • 69