I have a string
let String = " Test ";
I need an output as below:
Output = Test
I have tried using trim()
, trimstart()
, trimend()
Only one space has been removed using these scalar functions.
I have a string
let String = " Test ";
I need an output as below:
Output = Test
I have tried using trim()
, trimstart()
, trimend()
Only one space has been removed using these scalar functions.
Please try trim
with Regex \s
for whitespaces:
let String = " Test ";
print a = String, b = trim(@"\s", String)
Found the work-around using replace_regex(source,lookup_regex, rewrite_pattern)
Pass the string value as source, lookup_regex as " " (nothing but blank spaces), rewrite_pattern as "" (replace with no space)
Example:
Input: let String = " Test "; //String length is 11
print(replace_regex(String," ", "")) Output is: Test (String length is 4)
--Happy Coding:)
To replace more than one trailing and leading space character , We can use regular expression [trim(@"[ \t]+",<string_to_replace>)]
in trim
let String = " Te. se st. ";
print original_string = String replacing_all_space_via_regex= trim(@"[ \t]+",String)
//Other possible methods to replace just the single occurrence of space
//print original_string = String, replacing_single_space_via_space_character = trim(@" ", String)
//print original_string = String replacing_single_space_via_regex = trim(@"[ \t]",String)