How to remove multiple spaces from any string being strictly defined by the user?

How to remove all multiple spaces and replace it with single space or how to join all of them into one. Like what is the output string, can anyone give us an example.


Welcome to our UiPath community.

Can you please tell more details about your query for better understanding.

@lakshman Thank you for your greetings. I just wanted to remove whatever the spaces the input string has. User will provide me a table name and I have to process that into the database. Before I do that I want to ensure that the table name has no spaces at all.

Like if Table Name is: " Samarth Papers Bala Bla Bla "
The output I am expecting is: “SamarthPapersBalaBlaBla”

Thanks in advance!


Let’s say

strInput = " Samarth Papers Bala Bla Bla "

           strOutput = strInput.Trim.Replace(" ","")
1 Like

@lakshman Actually I had put multiple spaces, but after clicking on reply button, multiple spaces is removed by default. So let’s say if I have an input String say like mention below:

strInput = “-----Samarth–Papers—Bala–Bla-Bla-----” (where " - " indicates spaces)

strOuput expected = SamarthPapersBalaBlaBla.

Thank you!


Try below expression.

           strOutput = System.Text.RegularExpression.Regex.Replace(strInput, " {2,}", "").Replace(" ","")

Error: ‘RegularExpression’ is not the member of ‘text’.

Hey @Akash_Khobare

Only using String Replace should work fine.

Is it not giving you the output.


@Nithinkrishna Thanks for interfering, but how can I replace spaces which can be dynamic. For instance, say I have the input as following:

in_str = “…I…love…to…play…badminton…”
out_str = “”

In all above expressions " . " represents space.

1 Like

Hey @Akash_Khobare

It doesn’t matter. String.Replace will replace all the occurance of space character in the text.

Str_Value.Replace(" ", String.Empty)

Hope this helps.


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