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