How to make a replace in a string irrespective of string length?

Hello All,

I need to replace certain characters in string irrespective of the length of the string.

I need to replace all the character which are in between first 6 characters and last four characters with XXXXX

For example:
String1: 123456789101112
String2:1234567891234567891
String3:1231231231231233

any leads or helps are much appreciated.

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"(?<=^.{6}).*(?=.{4}$)",Function(m) New String("X"c, m.Value.Length))

Regards,

1 Like

@Sirimalla_Karthik_Chandra Please find below workflow

Capture

Regex.zip (2.4 KB)

1 Like

Hi @Yoichi, Thank you so much for helping me again.

I need another help as well. Can we extract data from a string in between first 6 characters and last 4 characters irrespective of length of the string.

Hi @ushu, Thank you much for the help.

We only have to replace the same number of characters with “X’s” in the string.

For example
String1: 1234567891234 has length of 13 characters. And the output should look like
123456XXX1234.

Length of the string should be equal after doing the replace. However I got the solution from @Yoichi.

I need another help as well. Can we extract data from a string in between first 6 characters and last 4 characters irrespective of length of the string.

with the same pattern from @Yoichi you can extract the middle string with Regex.Match

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=^.{6}).*(?=.{4}$)").Value

For stepping into the topic of Regex also have a look here:
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

1 Like

Hi @ppr , Thank you man for helping me out.

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