【发布时间】:2013-02-21 04:59:03
【问题描述】:
您知道如何获取QString 中可能参数的数量吗?
我想做这样的事情:
int argumentCount = countArguments(QString("This is the %1 argument, this is the %2 one")`);
结果应该是argumentCount == 2。
【问题讨论】:
您知道如何获取QString 中可能参数的数量吗?
我想做这样的事情:
int argumentCount = countArguments(QString("This is the %1 argument, this is the %2 one")`);
结果应该是argumentCount == 2。
【问题讨论】:
你可以使用regular expressions和QString::count函数:
QString str1("%1%2 test test %3 %4 %555");
int n = str1.count(QRegExp("%\\d+"));//n == 5
更新: 因为 QString 的 arg 数字可以在 1-99 范围内,所以可以使用这个 reg-exp:
QString str1("%1%2 test test %3 %4 %555");
int n = str1.count(QRegExp("%\\d{1,2}(?!\\d)"));//n == 4
【讨论】:
QString::arg() 的参数范围是 %1-99;该怎么做?