0

I have a QStringList with many elements, for example:

sl.at(i) = name:VAR1 size: 8 Decription:fdgag; 

how can i split this line into more lines? I want to split line by line into more lines with for-loop.

thats what i have:

for(int i = 0; i != sl.size(); ++i)
{
   QString str = sl.at(i);
}

But then I don't know how I can split this...

demonplus
  • 5,613
  • 12
  • 49
  • 68
mc307
  • 19
  • 1
  • 4

2 Answers2

1

If you want to split a string by space-character just use the function mentioned earlyer with space

QStringList split = str.split(" ");
JSilver
  • 107
  • 6
0

Take a look at the QString::split() functions:

for(int i = 0; i != sl.size(); ++i) {
    QString str = sl.at(i);
    // Split on , 
    QStringList splitStr = str.split(", ");
}
CJCombrink
  • 3,738
  • 1
  • 22
  • 38
  • sorry i dont have a comma, i have a space character there – mc307 Oct 20 '15 at 06:17
  • if i do this: QString str = slOut.at(i); strsplit = str.split("\\t+"); it doesnt work – mc307 Oct 20 '15 at 06:25
  • Is it a single tab char between your strings? If yes, then you need ("\t"), by using double slash you are escaping the slash which means a slash character followed by a t and a plus. However, if you want to use a Regular Expression you need to make it clear to the function: str.split(QRegularExpression("\\t+")); – CJCombrink Oct 21 '15 at 06:16