qt中利用正则表达式提取字符串中的浮点数和整数
转载:https://blog.youkuaiyun.com/talkingmute/article/details/121948961
直接上代码
//取字符串中最后一个数字
static bool splitRx(const QString& string, qulonglong& value, int &pos,int& length)
{
// QRegExp rx("(\\d+)"); //整数
QRegExp rx("\\d+\\.\\d+|(\\d+)"); //整数+浮点数
int index = 0;
while ((index = rx.indexIn(string, index)) != -1)
{
pos = index;
length = rx.matchedLength();
index += length;
value = rx.cap(0).toDouble();
}
return index != 1 ? true : false;
}
本文分享了如何在Qt中使用正则表达式splitRx函数,通过QRegExprx匹配整数和浮点数,从字符串中提取并解析数值。适合理解和实践在C++开发中处理文本数据的场景。
1208

被折叠的 条评论
为什么被折叠?



