M
M
mat0thew2015-05-01 16:21:22
Qt
mat0thew, 2015-05-01 16:21:22

How to split a string into separate arrays?

I have this code.

QRegExp rx("(\\\n|\\:|\\;)");
QString myString("[email protected];pass\[email protected];pass2\[email protected]:pass3");

QStringList myStringList = myString.split(rx);

for (int index = 0; index < myStringList.length(); index++)
{
    std::cout << "[" << index << "] " << myStringList.at(index).toStdString() << std::endl;
}

At the output, I get this:
rvnbs.png
The task is to get an array of this kind:
[0][1] [email protected]
[0][2] pass
[1][1] [email protected]
[1][2] pass2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rmaksim, 2015-05-01
@rmaksim

I don’t know how it is in C ++, but if these are algorithms, then in javascipt it would be like this

var str = "[email protected];pass\[email protected];pass2\[email protected]:pass3"
var arr = str.split("\n").map(function(x){return x.split(/;|:/)})

those. first split by "\n", we get one array with soap and password
and then resp. we split each such element by ":" or ";"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question