Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]How to remove the spaces before and after two words but not remove the space between the two words?

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    slumberdin
    wrote on last edited by
    #1

    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:

    @
    ui->lineEdit->setInputMask("nnnnn");
    if (ui->lineEdit->text()== NULL)
    {
    QMessageBox::warning(this,tr("Warning"),
    tr("NULL"),
    QMessageBox::Ok) ;
    return;
    }
    else
    ui->textBrowser->setText(ui->lineEdit->text());
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        slumberdin
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            slumberdin
            wrote on last edited by
            #5

            ok, thanks Andre...

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved