-2

I have the QString line like this "567\n1.23456 2.34567\n1.23456 2.34"

And I want only "whole" float numbers only between \n characters.

I need QStringList after split() that contains only this float numbers. QString::split() can use RegEx so maybe I can use som regex here.

i tried QStringList myList = QString("56\n1.12345 2.34567\n1.23456 2.34").split('\n') that returns me ["1.2345 2.34567"] so i need split this again to ["1.23456"] and ["2.34567"]

Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63
AmeZir
  • 1
  • 2

3 Answers3

0

this regex \d+(\.\d+)? will give you any float/int number!

xrq0
  • 119
  • 13
0

You should split at QRegularExpression("\\s+"). \s means whitespace (which includes both =space and \n=newline), + means one or more, and you need to escape the backslash.

Martin Hennings
  • 16,418
  • 9
  • 48
  • 68
0

The Qt documentation for QString::split has your answer

QString str;
QStringList list;
str = "Some  text\n\twith  strange whitespace.";
list = str.split(QRegularExpression("\\s+"));
// list: [ "Some", "text", "with", "strange", "whitespace." ]
zeFrenchy
  • 6,541
  • 1
  • 27
  • 36
  • yes and after split i have 56, 1.12345 2.34567 1.23456 2.34, but i only need float numbers surrounded by "\n" characters. – AmeZir Aug 15 '19 at 09:22
  • 1
    Then use split twice ... once using QChar('\n'), then using QChar(' ') or QRegularExpression("\\s+") depending on how reliable the whitespace between the floats is. – zeFrenchy Aug 15 '19 at 09:24