QString::mid question

  • Hi i checked all but one thing i never can get is for example i have this string.
    QString string= "change"
    "abcde"+ string + "ijklm"
    Sometimes the length of my string change. How i can start counting since right and get complet string for example i start since letter k so i will get:
    "abcde"+ change + "ijk"

    Sorry if i was explaining bad but i want to count since right with mid. thx

  • Lifetime Qt Champion


    Do you mean get the length length of "ijk" or get the length of "abcde" + some_string + "ijk" ?

  • @SGaist said in QString::mid question:

    "abcde" + some_string + "ijk"

    "abcde" + some_string + "ijk" if the some_string change each time the length.

  • This will return the number of code points of the combined string:


  • I think what @RIVOPICO is trying to say (I could be completely wrong), is:

    • he already has a string like abcdesome_stringijklm
    • he wants to use QString::mid() to extract just some_string, but of course, QString::mid() requires a substring lengh, which is unknown in this case.

    If I read @RIVOPICO correctly, then he could do something like: string.mid(6, string.length()-11); ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.