Check a specific number and change it

Hi UiPath community!

I would really appreciate some help with the following issue:
I have a number (Eg: 151), and I have to check two things:

  • Is it a three digit number?
  • Does it start with “1”?

If yes to both those conditions, I have to replace the first “1” with “0”. Thus, “151” should be changed to “051”. Unfortunately, I cannot simply subtract 100 from the number as the result will be “51”. Are there any other ways to do this? Can anyone help me with this?

Thanks!

1 Like

Hi,

If your variable type is Int32, the following will work.

System.Text.RegularExpressions.Regex.Replace(intVar.ToString(),"^1(?=\d\d$)","0")

If your variable type is string, can you try the following?

System.Text.RegularExpressions.Regex.Replace(text,"^1(?=\d\d$)","0")

Regards,

4 Likes

Thank you so much for your swift response! I tried both methods, and they worked perfectly! :grinning:

Is there a way I could check for the conditions I mentioned in the post? I need to use a Flow Decision in the workflow!

1 Like

Hi,

We can use IsMatch method as the following.

System.Text.RegularExpressions.Regex.IsMatch(intVar.ToString(),"^1(?=\d\d$)")

This expression returns true if intVar start with 1 and has 3 digits.

Regards,

1 Like

Worked perfectly! Thanks very much. I really appreciate your help!

1 Like

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