How to remove extra spaces between words in a string, leaving only one space?
Hello ZH T,
Use below JS function and pass your string as a parameter, it will return you the desired string as an output.
function removeExtraSpaces(inputString) {
// Use regular expression to replace 1 to 200 spaces with a single space
return inputString.replace(/\s{1,200}/g, ' ');
}
// Example usage
var inputString = $Inputparameter
$outputparameter = removeExtraSpaces(inputString);
Example:
Inputparameter = "India USA China UK"
outputparameter = "India USA China UK"
Also refer to the oml provided.
Hope that helps.
Regards
Anees
@Mohd Anees Mansoori , Thank you!
Hey @ZH T
I made a brute-force solution for this
i am looping the variable until there are no 2 spaces left and I keep replacing 2 spaces with 1
EDIT: If Condition (Index(Var1," ") <> -1) and Assign: Replace(Var1," "," ")
After that, you can run trim to make sure do not have any leading and trailing spaces
Hope this helps
Regards,Kshitij
Hi @ZH T,
Use below JS function below and pass your input string as a parameter, it will return the Expected output.
function removeSpaces(input)
{
return input.replace(/\s+/g, ' '); // Use regular expression to replace Multiple spaces with a single space