Ask a Question

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

SOLVED
viniciuscandido
New Contributor

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?

1 REPLY 1
8Kit
Frequent 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.   

cancel
Showing results for 
Search instead for 
Did you mean: