怎么解析这个数据
QStringm="SSLL:000001.12 ZZLL:000006488152";把里面的两个数据提取出来一个浮点数一个整数
QStringm="SSLL:000001.12 ZZLL:000006488152";
QStringList Query = m.split(QRegExp("(\\ |\\:)"), QString::SkipEmptyParts);
double d = Query.at(1).toDouble();
int i = Query.at(3).toInt();
qDebug() << d << " - " << i;
用正则表达式:
QString m = "SSLL:000001.12 ZZLL:000006488152";
QRegularExpression reg("+");
QRegularExpressionMatchIterator i = reg.globalMatch(m);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
if(match.hasMatch()) {
QString capture = match.captured(0);
qDebug() << capture;
if(capture.contains("."))
qDebug() << "浮点数" << capture.toDouble();
else
qDebug() << "整数" << capture.toInt();
}
}
输出:
"000001.12"
浮点数 1.12
"000006488152"
整数 6488152
页:
[1]