Split a String at prompt "."
-
Hello,
i have a Question About Splitting a string. Is it possible to use the QRegularexpression die split a QString on "."? And when it is possible, how can i do that?
i Tryed:
List = String.Split(QRegularExpression(".")), but that does not work. -
-
Thank you for this quick answer. I tried that way before but i got a Syntax Error, dont know which one exactly.
It worked using List = String.Split(QRegularExpression("\\.")) -
@meikelneit said in Split a String at prompt ".":
. I tried that way before but i got a Syntax Error,
Did you use
.
(dot) as a string or char? -
I just hitted my dot button :P, how do i know if its a char or a string? Shall i use the Hexcode of the Ascii?
ps: yes ";" is no Problem. Try it with "."
-
@meikelneit
I hope I understand your problem, my English isn't good :(
Anyway, It works well with "." -
@meikelneit said in Split a String at prompt ".":
how do i know if its a char or a string?
"." -> implicit QString
'.' -> implicit QCharQString(".");
QChar('.');' more than 1 character' -> Compiler error.
-
@meikelneit said in Split a String at prompt ".":
Try it with "."
Split works both with string and char as
split
has overloads withstring
andchar
. -
I just can tell u what happens when i try to split with ".".
the line i tryed to split is: Array[0..3] of Int;
when i use "." is QRegularexpression to split with, i get 21 List Elements and every single one is empty.
it wokrs without error, but pls have a look into your listelements, mine were empty, and i had 21 of them, i expected 3. -
@meikelneit Can you show your code including the exact string you're trying to split?
-
@meikelneit said in Split a String at prompt ".":
mine were empty, and i had 21 of them, i expected 3.
The second argument to
split
takes care of this: https://doc.qt.io/qt-5/qstring.html#split-3 -
Split function works well in both cases:
- QStringList list = text.slit(".");
- QStringList list = text.split(";");
If it is what you want to know, be patient if I didn't well understand
Also I tried:
- QStringList list = text.slit(‘.’);
- QStringList list = text.split(‘;’);
Also in this cases split works well.
-
Hi
@meikelneit said in Split a String at prompt ".":
(QRegularExpression(".")
The dot in regular expressions means any character. As you discovered, if you want to express a literal dot you have to escape it.
You can test your expressions with the QRegularExpression example tool.
-
Thank you very mutch, that explains why i have 21 empty listelements. It just splits between every single character. :) ok thx