How to use multiple condition in replace activity

i want to replace 5 blank space to single space, 6 blank space to single space and 9 blank space to single space in the same string
can replace activity do it.

Hi @ashishmani,

Please try with Regex. Hope you have stored the string into a String Variable.

Now, try the below -
Regex.Replace(Your_String_Variable,"\s+"," ")

Hope it will help you.

Thanks & Regards,
Apurba

1 Like

the best way for this is using regex. For you case try this:

system.Text.RegularExpressions.Regex.Replace(your_string,"\s{5}"," β€œ) and
system.Text.RegularExpressions.Regex.Replace(your_string,”\s{6}"," ")

\s represent any space character

How use it?

Put a assign activity ->
your_string = system.Text.RegularExpressions.Regex.Replace(your_string,"\s{5}"," ")

Just remember that you should first do the 9 space, then the 6 space, then the 5 space replace in that order :wink:

1 Like

hi @ ashishmani,

or use replace in norlam

Like
to 5
YourString = YourString.Reaplce(" β€œ,” β€œ) <-- 5 Times Space
to 6
YourString = YourString.Reaplce(” β€œ,” β€œ) <-- 6 Times Space
to
YourString = YourString.Reaplce(” β€œ,” ") <-- 9 Times Space

this AND condition is not working here

there is no AND condition there, just do the replace 3 times one after the other…

my string type is "System.string[ .]

im gwtting error

Please look at this: Main.xaml (5.0 KB)

@ashishmani

In your screenshot seems like … your code having extra " and . remove last two digit in your code &

system.Text.RegularExpressions.Regex.Replace(your_string,"\s{5,9}"," ")

more than one Space use below code

system.Text.RegularExpressions.Regex.Replace(your_string,"\s{2,}"," ")

1 Like

regexReplace.xaml (6.0 KB)

Regex.Replace(inputStr,"(\s{9}|\s{6}|\s{5})"," ").ToString

Thanks!

1 Like

getting error

1 Like

Please provide your input string or xaml.

error

1 Like

Use a for each then…

still getting error
image

1 Like

ashishmani

use like you have in expression editor and lines.toString,"\s…

1 Like