How to remove the first two characters of a QString

Joe Carr picture Joe Carr · Mar 7, 2017 · Viewed 19k times · Source

How would I remove the the first two characters of a QString or if I have to put it a StackOverflows layman's terms:

QString str = "##Name" //output: ##Name

to

output: Name

So far I have used this small piece of code:

if(str.contains("##"))
{
    str.replace("##","");
}

..but it doesn't work as I would need to have "##" in some other strings, but not at the beginning.

The first two characters may occur to be "%$" and "#@" as well and that mostly the reason why I need to delete the first two characters.

Any ideas?

Answer

PLAYBOY picture PLAYBOY · Mar 7, 2017

This the syntax to remove the two first characters.

str.remove(0, 2);