Qt String Parsing

<>

This question already has an answer here:

Answers


QString str = "Bob 1, 2, 3";

QRegExp rx("[, ]");// match a comma or a space
QStringList list = str.split(rx, QString::SkipEmptyParts);

qDebug() << list;

QString name = list.at(0);
QList <int> nums;
for(int i = 1; i < list.size(); i++)
{
    nums.append(list.at(i).toInt());
}

qDebug() << "Name:" << qPrintable(name);
//    foreach(int num, nums)
//    {
//        qDebug() << "num:" << num;
//    }
for(int i = 0; i < nums.size(); i++)
{
    qDebug() << qPrintable("num" + QString::number(i+1) + ":") << nums.at(i);
}

output

("Bob", "1", "2", "3") 
Name: Bob 
num1: 1 
num2: 2 
num3: 3 

Need Your Help

How to add a time interval to an NSDate?

objective-c cocoa cocoa-touch nsdate date-arithmetic

I have an NSDate and a duration. I need to get the time after the duration

Trouble with SVN post-commit and Jenkins

svn jenkins post-commit-hook

I am trying to get CI going with Jenkins. To date, we have been performing two scheduled builds in our environment, but our dev staff wants to get CI working. I have followed the instruction outl...