Using replace function



  • 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 ?



  • 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
    @



  • 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.


Log in to reply
 

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