# Replace multiple characters in a string with "-"

**URL:** <https://forum.uipath.com/t/replace-multiple-characters-in-a-string-with/279195>\
**Category:** Help\
**Tags:** string, question, system, activities\
**Created:** [December 24, 2020, 8:27am UTC](https://forum.uipath.com/t/replace-multiple-characters-in-a-string-with/279195 "2020-12-24T08:27:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jntrk](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@jntrk](https://forum.uipath.com/u/jntrk)\
**Post date:** [December 24, 2020, 8:27am UTC](https://forum.uipath.com/t/replace-multiple-characters-in-a-string-with/279195/1 "2020-12-24T08:27:23Z")

</div>

Hey everyone,

I have a simple string question,  
I have a variable where I get the input from the user, and what I want to do is if user gives

/ , \ , \* , : , ? , " , \> , \< , | inside the string I want to replace all with " - ".

so for example string= hi/my\*\?name\<\>  
after replacement it should be hi-my—name–

Any suggestions?  
Maybe some single execution solution?

---

<div class="post-metadata">

**Author:** ![jack.chan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jack.chan/32/176616_2.png) [@jack.chan](https://forum.uipath.com/u/jack.chan)\
**Post date:** [December 24, 2020, 8:38am UTC](https://forum.uipath.com/t/replace-multiple-characters-in-a-string-with/279195/2 "2020-12-24T08:38:19Z")

</div>

Heres a solution

1. assign this to a string variable e.g. “result” , where “input” is your string input,  
this will replace any / , \ , \* , : , ? , " , \> , \< , | that it finds  
`System.Text.RegularExpressions.Regex.Replace(input,"[\/\\*:\?\"+Chr(34)+"><|]","-")`

Note that Chr(34) means double quote, as you cant just place a double quote inside a string

![image](https://global.discourse-cdn.com/uipath/original/3X/0/d/0d4607ff97ef4573c1faa47a0c727a163a6dedfb.png)

 ![image](https://global.discourse-cdn.com/uipath/original/3X/2/b/2b51b7165c3e4c6b41458e2bb2716b920e342910.png)

---

<div class="post-metadata">

**Author:** ![jntrk](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@jntrk](https://forum.uipath.com/u/jntrk)\
**Post date:** [December 24, 2020, 9:29am UTC](https://forum.uipath.com/t/replace-multiple-characters-in-a-string-with/279195/3 "2020-12-24T09:29:46Z")

</div>

> [@jack.chan](#):
>
> 1. `System.Text.RegularExpressions.Regex.Replace(input,"[\/\\*:\?\"+Chr(34)+"><|]","-")`

Works like a charm. Thank you

---

<div class="post-metadata">

**Author:** ![jack.chan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jack.chan/32/176616_2.png) [@jack.chan](https://forum.uipath.com/u/jack.chan)\
**Post date:** [December 24, 2020, 9:47am UTC](https://forum.uipath.com/t/replace-multiple-characters-in-a-string-with/279195/4 "2020-12-24T09:47:38Z")

</div>

No problem, good luck!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [December 27, 2020, 9:47am UTC](https://forum.uipath.com/t/replace-multiple-characters-in-a-string-with/279195/5 "2020-12-27T09:47:44Z")

</div>

Closed on December 27, 2020, 9:47am UTC

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