【问题标题】:Count QString arguments计数 QString 参数
【发布时间】:2013-02-21 04:59:03
【问题描述】:

您知道如何获取QString 中可能参数的数量吗?

我想做这样的事情:

int argumentCount = countArguments(QString("This is the %1 argument, this is the %2 one")`);

结果应该是argumentCount == 2

【问题讨论】:

    标签: qt qstring


    【解决方案1】:

    你可以使用regular expressionsQString::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
    

    【讨论】:

    • 哇。我真的需要更多地了解它们...*sight* 最后一个问题...QString::arg() 的参数范围是 %1-99;该怎么做?
    • 当然 :) here 是一个很好的起点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-21
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    相关资源
    最近更新 更多