Remove empty spaces in string

Hi, can I please get help to remove all of these empty spaces:

Hi @Anelisa_Bolosha1
store all in “InputString” variable and then use like below expression

OutputText = Regex.Replace(InputString, “\s+”, " ").Trim

OR

OutputText = Regex.Replace(InputString, " {2,}", " ")

happy Automation

2 Likes

Hi @Anelisa_Bolosha1

Save that string in emailbody variable and use the below command

cleanedBody = System.Text.RegularExpressions.Regex.Replace(emailBody, "^\s*$[\r\n]*", String.Empty, System.Text.RegularExpressions.RegexOptions.Multiline) 

or

cleanedBody = System.Text.RegularExpressions.Regex.Replace(cleanedBody, "\s{2,}", " ")

Thanks!!

Hello @Anelisa_Bolosha1,
Try this by Assign Activity:

YourString = String.Join(Environment.NewLine,YourString .Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries))

Or
Try this :
System.Text.RegularExpressions.Regex.Replace(yourString,“^\s+”,“”,System.Text.RegularExpressions.RegexOptions.Multiline).Trim

Thanks
Andy

This seemed to solved it, thank you so much

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.