yangzi8000 发表于 2023-5-6 15:12:27

怎么解析这个数据

QStringm="SSLL:000001.12 ZZLL:000006488152";
把里面的两个数据提取出来一个浮点数一个整数

chenycs 发表于 2023-5-8 08:34:00

        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;

snolkmg 发表于 2023-5-9 09:17:34

用正则表达式:
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]
查看完整版本: 怎么解析这个数据