Replace space in between two strings

Hi, I want to replace space in between two strings with %20. Example Input - Welcome To Ui Path Forum Output Should be - Welcome%20To%20Ui%20Path%20Forum .

Hi @sunny.allawat

Try this

String.Join("%20", Input.Split(" "c))

Cheers!!

@sunny.allawat

String.Join("%20", Input.Split(" "c))

Cheers!!

@sunny.allawat,

Welcome to the UiPath Community :tada:

For this we have readymade solution.

Use this in assign activity

System.Web.HttpUtility.UrlPathEncode("Welcome To Ui Path Forum")

image

Output:
image

Thanks,
Ashok :slight_smile:

we suggest
grafik

As
grafik
And
grafik

@sunny.allawat I hope it will solve your issue you can use the regex or you can use spacial char key value to replace

Method 1: Using String.Replace

  1. Import the System.Text namespace (if not already imported):
  • In the Properties panel of your workflow, go to the Imports tab.
  • Click “Import” and select “System.Text”.
  1. Create a string variable:
  • In the Variables panel, add a new String variable. Name it appropriately, for example, “modifiedString”.
  1. Use the String.Replace function in an Assign activity:
  • Drag an Assign activity onto your workflow.
  • In the “To” property of the Assign activity, set it to the new variable (e.g., modifiedString).
  • In the “Value” property, use the following expression:
System.Text.RegularExpressions.Regex.Replace(yourStringVariable, " ", "%20")

Replace yourStringVariable with the actual variable containing the string with spaces.

Explanation:

  • System.Text.RegularExpressions.Regex.Replace function is used for replacing patterns in strings.
  • " " (space within quotes) is the pattern we’re searching for (spaces).
  • "%20" is the replacement string (%20 for URL encoding).

Method 2: Using String Manipulation Activities (UiPath v20.10 or above)

  1. Use the String Manipulation - Replace activity:
  • Drag a String Manipulation activity and select “Replace” from the dropdown.
  1. Set the properties:
  • In the “Input” property, enter the variable containing your string with spaces.
  • In the “Find” property, enter a space (" ").
  • In the “Replace With” property, enter “%20”.

Both methods achieve the same outcome of replacing spaces with %20 in your string.
Choose the method that best suits your UiPath version and workflow preference.

Note: maybe it’s required to change the regex or logic according to your needs

Or below solution also work for your case.

  1. String.Join and Split (by @lrtetala ):

This method uses the String.Join and Split functions.

  • Split(" "c) splits the string based on spaces (" ").
  • String.Join("%20", ...) joins the split parts back together, inserting “%20” between each element.
  1. System.Web.HttpUtility.UrlPathEncode (by @ashokkarale ):

This method uses the built-in System.Web.HttpUtility.UrlPathEncode function specifically designed for URL encoding. It handles various characters and converts them to their encoded format.

thanks to all for helping me . it is resolved now

1 Like

Hi ashok

one more thing i am new with UI , i want to apply the same over 1000 record in excel but while i am Appling it with loop getting error . can you help me on the same ?

@sunny.allawat ,

Sure. Share the details in PM i will look into it

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