我想得到一个 Qstring
的第一个词.
例如 String1 = "Read from file1"
.我要提取string2 = "Read"
.
我想根据空格提取子字符串。
如果我在 string1
中遇到第一个空格,我需要string1
的那部分至 string2
.
最佳答案
使用QString
的拆分功能通过这种方式:
QString firstWord = string1.split(" ").at(0);
如果字符串中没有空格,则返回整个字符串。
关于qt - 如何从 Qstring 中获取第一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21604722/