Regular expression that will isolate numbers and text.
QString text
= "5001 1001 5002 1002.5 Observation reason: 10 river and pond."
int pos = 0;
while ((pos = rx.indexIn(text,pos)) != -1){
linesInt << rx.cap(1);
pos += rx.matchedLength();
}
//linesInt = (5001, 1001, 5002, 1002, 5, 10) --- I want linesInt = (5001, 1001, 5002, 1002.5)
//or linesInt = (5001, 1001, 5002, 1002.5, Observation reason: 10 river and pond.)
QStringList linesInt;
QRegExp rx("(\\d+)");
QString text = "5001 1001 5002 1002.5 Observation reason: 10 river and pond."
int pos = 0;
while ((pos = rx.indexIn(text,pos)) != -1){
linesInt << rx.cap(1);
pos += rx.matchedLength();
}
//linesInt = (5001, 1001, 5002, 1002, 5, 10) --- I want linesInt = (5001, 1001, 5002, 1002.5)
//or linesInt = (5001, 1001, 5002, 1002.5, Observation reason: 10 river and pond.)
To copy to clipboard, switch view to plain text mode
The code below give me the result I expect. But I would have to test if the first 4 are numbers.
QString text
= "5001\t1001\t5002\t1002.5\tObservation reason: 10 river and pond." linesInt
= text.
split(rx,
QString::SkipEmptyParts);
//linesInt = (5001, 1001, 5002, 1002.5, Observation reason: 10 river and pond.)
QStringList linesInt;
QRegExp rx("\t");
QString text = "5001\t1001\t5002\t1002.5\tObservation reason: 10 river and pond."
linesInt = text.split(rx,QString::SkipEmptyParts);
//linesInt = (5001, 1001, 5002, 1002.5, Observation reason: 10 river and pond.)
To copy to clipboard, switch view to plain text mode
Someone would indicate a QRegExp?
Bookmarks