-1

I want to show sub string after "<". for example I have this statements:

input:

" o <kpl"  

output:

"<kpl"

input:

"h123 l<"

output:

"<"

How to do that?

demonplus
  • 5,613
  • 12
  • 49
  • 68
Farzan Najipour
  • 2,442
  • 7
  • 42
  • 81

1 Answers1

3

You can use mid() for that:

QString input = "h123 l<";
int index = input.indexOf('<');
if (index  != -1)
{
    QString output = input.mid(index);
}
demonplus
  • 5,613
  • 12
  • 49
  • 68
  • I think, you don't need this `if (index != -1)` check. – vahancho Nov 19 '15 at 08:32
  • Just in case you want to process two cases separately, when characher is found and when is not – demonplus Nov 19 '15 at 08:34
  • @vahancho: It won’t crash, but if it is needed or not depends on how the code should behave when there’s no “<“. Full string? Empty string? – Frank Osterfeld Nov 19 '15 at 09:07
  • @FrankOsterfeld, my point was that `input.mid(-1)` will return the original string. Yes, the code depends on how missing '<' should be interpreted. – vahancho Nov 19 '15 at 09:34