#include <vector>
using namespace std;
vector<double> getNumListFromStr(const QString& str)
{
QRegExp rx("-?[1-9]\\d*\\.\\d*|0+.[0-9]+|-?0\\.\\d*[1-9]\\d*|-?\\d+");
int pos = 0;
vector<double> v;
while ((pos = rx.indexIn(str, pos)) != -1)
{
pos += rx.matchedLength();
v.push_back(rx.cap(0).toDouble());
}
return v;
}
Qt使用正则表达式从字符串中提取数值
最新推荐文章于 2023-11-05 21:55:35 发布
本文介绍了一种使用正则表达式从给定的字符串中提取所有浮点数,并将其转换为C++标准库vector<double>类型的实用方法。这种方法适用于需要从文本数据中快速获取数值列表的场景。
2820

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



