Forum Discussion

viniciuscandido's avatar
viniciuscandido
New Contributor
3 years ago

aqString.Trim does not remove all spaces from the specified string

Hey everyone! ðŸ‘‹

The function aqString.Trim() only removes leading and trailing spaces, if a given string has a whitespace within, this one is not removed. 

 

Example of using Trim function:

function test(){
let str = " this is an example ";
Log.Message(aqString.Trim(str)); //returns: "this is an example"
}

The code that worked for me was:

function test(){
let str = " this is an example ";
Log.Message(aqString.Replace(str, " ", "")); //returns: "thisisanexample"
}

 

Is it safe to continue with this solution? Will there be an improvement to the aqString.Trim function to remove all whitespace from a string?

  • That is what the Trim() method is designed to do, only remove leading or trailing spaces. Likewise, if you want to replace all spaces with nothing, you would you the Replace() method as you have discovered. There should be no issues with how your test performs.   

  • Kitt's avatar
    Kitt
    Regular Contributor

    That is what the Trim() method is designed to do, only remove leading or trailing spaces. Likewise, if you want to replace all spaces with nothing, you would you the Replace() method as you have discovered. There should be no issues with how your test performs.