Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Using replace function
Forum Updated to NodeBB v4.3 + New Features

Using replace function

Scheduled Pinned Locked Moved Qt Creator and other tools
3 Posts 2 Posters 2.3k 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.
  • D Offline
    D Offline
    dMathieuD
    wrote on last edited by
    #1

    Hi,
    I'm trying to remove space in a string using "replace" function in my project file. I tried a lot of different things like:
    @
    myNewVariable = bla bla
    myNewVariable = $$replace($${myOldVariable}, " ", "")
    @
    or

    @
    myNewVariable = bla bla
    myNewVariable = $$replace(myOldVariable," ","")
    @
    or

    @
    myNewVariable = bla bla
    myNewVariable = $$replace(myOldVariable,' ','')
    @
    or

    @
    myNewVariable = bla bla
    SPACE = ' '
    EMPTY = ''
    myNewVariable = $$replace($${myOldVariable}, $${SPACE},$${EMPTY})
    @
    or

    @
    myNewVariable = bla bla
    SPACE = ' '
    EMPTY = ''
    myNewVariable = $$replace(myOldVariable,SPACE,EMPTY)
    @
    Each time I get myNewVariable empty.

    Did I miss something ? Is it something not possible to do with replace function ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      What the hell? You're supplying the wrong variable name to replace. And you need to enclose a string with spaces in quotes.

      @
      VAR = "foo bar baz"
      VAR = $$replace(VAR, ' ', '')
      message($$VAR)
      @

      correctly prints

      @
      Project MESSAGE: foobarbaz
      @

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dMathieuD
        wrote on last edited by
        #3

        Sorry for bad edition I was meaning:

        @
        myNewVariable = bla bla
        myNewVariable = $$replace(myNewVariable,' ','')
        @
        And indeed this is working but it was a bit more complicated for me as I was using "system" function like this:
        @
        myOldVariable = "Foo Bar Baz"
        myNewVariable = $$system(echo $${myOldVariable} | tr 'A-Z' 'a-z')
        myNewVariable = $$replace(myNewVariable,' ','')
        @
        which prints
        @
        Project MESSAGE: foo bar baz
        @
        but this:
        @
        myOldVariable = "Foo Bar Baz"
        myNewVariable = "$$system(echo $${myOldVariable} | tr 'A-Z' 'a-z')"
        myNewVariable = $$replace(myNewVariable,' ','')
        @
        correctly prints:
        @
        Project MESSAGE: foobarbaz
        @
        But the best way to do the trick for me is like that:
        @
        myOldVariable = "Foo Bar Baz"
        myNewVariable = $$lower($$myOldVariable)
        myNewVariable = $$replace(myNewVariable,' ','')
        @

        It's such a shame that functions like "lower" or "upper" are not documented in the official documentation at http://doc.qt.nokia.com/4.7/qmake-function-reference.html. Is there good reasons for that? For those looking for more documentation about qmake you can have a look at http://www.qtcentre.org/wiki/index.php?title=Undocumented_qmake.

        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