1
您知道如何获得QString
中可能参数的计数吗?计数QString参数
我想要做的事,如:
int argumentCount = countArguments(QString("This is the %1 argument, this is the %2 one")`);
它的结果应该是argumentCount == 2
。
您知道如何获得QString
中可能参数的计数吗?计数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;怎么做? – Zaiborg 2013-02-20 20:06:45
我更新了我的答案。 – saeed 2013-02-20 20:40:24
感谢队友,这让事情变得如此简单:D – Zaiborg 2013-02-20 20:42:55