Deleting Extra Spaces in a String

Hello Forum!
I´m currently working on a UI automation where I have to extract text and so.
One of the text fields I have to extract is it´s a whole range of strings that can vary depending on the current Item. The thing is that this text is coming with a lot of white spaces…

I´ve tried RegEx replace method (“\s”,“”) and normal Replace string function. But nothing works.
So I also found a post here in the forum that talks about other solution (topic below)

So I had to try it out and see if it works. The thing is that I´m getting this error…

So I did the research but I failed to understand if it’s a namespace that I have to import and in that case, which one? Maybe the error is not about a new import.

So please someone provide me with some clarity on the matter, what should I do to solve the error? is there another solution for deleting the white spaces?
Hopefully, I will get an answer from the very Dear community.

Thank you very much



Can you share the string as a text file? WriteTextFileActivity will help you.


1 Like

Hi @Luis_Fernando

Use the following below syntax:

System.Text.RegularExpressions.Regex.Replace(cleanString, "\s+", " ")

Note: Attached the workflow for reference
Sequence11.xaml (7.9 KB)

Hope it helps!!

1 Like

Hello @Yoichi & @Parvathy
Thank you very much for your attention. Indeed the solution of our friend @Parvathy worked great!
PD: I also chat personally with @AkshaySandhu and also provide me with a similar solution that looked like this:
str_Input = “Some text with lot of white spaces "
strt_input = System.Text.RegularExpressions.Regex.Replace(strt_Input,”\s{1,500}“,” ")
The output will be “Some text with lot of white spaces”

Hopefully this way the post is helpful for other viewers.

Once again thank you for your attention.


Luis Fernando Pazos First Venezuelan RPA Developer.

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