如何确定 QString 中的特定字符是字母还是标点符号

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

本文关键字:标点符号 字符 QString 何确定      更新时间:2023-10-16

如何确定QString中的特定字符是任何语言的字母还是标点符号?

例如,我想在gâteau.中找到.,而不是â

尝试

str.at(i).isLetter()

对于 unicode 类 Letter_Uppercase/Smallcase/Titlecase/Modifier/Other,它将返回 true。你可以在这里看到:

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

你可以使用 at() 从 QString 中获取 QChar,QChar 有一个 isLetter() 函数。 因此,您需要类似以下内容:

QString myString;
if (myString.at(3).isLetter()) {
   qDebug() << "letter number 4 in the string is a letter";
}