Important: Please read the Qt Code of Conduct -

[Solved]How to remove the spaces before and after two words but not remove the space between the two words?

  • Hi everyone,
    I have difficulty in solving the above problem.
    I had encountered a problem in removing the space between the words.

    For example, when I put " <spaces> Hi everyone <spaces> ", I want only to get the string "Hi everyone".
    I came across this function, "setInputMask".
    But it still doesn't solve my problem.
    Can anyone help me?
    Maybe you can give some clue or explain on how exactly this function works?

    Btw, this is my code snippet:

    if (ui->lineEdit->text()== NULL)
    QMessageBox::Ok) ;

  • Lifetime Qt Champion


    Are you thinking of something like QString::trimmed() ?

  • Yup, SGaist.
    Thanks for the suggestion.
    That's really helps me. :)

  • There is also QString::simplified(). That one does a bit more, in that it also removes things like double spaces between words (reduces them to a single space), as well as trimming.

  • ok, thanks Andre...

Log in to reply