I have a String like below
I want to break the string in such a way that my output should be like belowQt Code:
To copy to clipboard, switch view to plain text mode
Output
0001f0
9f 80 2a 06 bd 40 23 5f
16 8c d8 37 43 fb b4 a4
I have a String like below
I want to break the string in such a way that my output should be like belowQt Code:
To copy to clipboard, switch view to plain text mode
Output
0001f0
9f 80 2a 06 bd 40 23 5f
16 8c d8 37 43 fb b4 a4
What does it mean not working as per expectation ?
I am getting the output as below
but my output should be like belowlist[0] = 0001f0
list[1] = 9f
list[2] = 80
list[3] = 2a
list[4] = 06
list[5] = bd
list[6] = 40
list[7] = 23
list[8] = 5f
list[9] = 16
list[10] = 8c
list[11] = d8
list[12] = 37
list[13] = 43
list[14] = fb
list[15] = b4
list[16] = a4
list[0] = 0001f0
list[1] = 9f 80 2a 06 bd 40 23 5f
list[2] = 16 8c d8 37 43 fb b4 a4
You ask to split with a space so what are you surprised ?
Is this string has a fixed format ? If yes just use QString::left, QString::mid and QString::right methods.
Something like this should work, if your lines are always formatted as you show (a 6-byte hex address first, followed by hex as 8 two-byte groups):
Qt Code:
QRegularExpression regExp( "^[0-9a-fA-F]6\\s+|(([0-9a-fA-F]2\\s+)8)+");To copy to clipboard, switch view to plain text mode
Untested, you might have to play around with the regular expression to get it working the way you want. You will probably also have to trim whitespace from the ends of the sub-strings because the regular expression includes the separators as part of the matching.
Last edited by d_stranz; 1st April 2016 at 17:27.
Bookmarks