How to replace last two digits with 00?

Hi All,

I have some list of Member ID like “123456709”, 234156808", “342516707” and so on first I want to check for the condition for each Member ID i.e whether the "last two digits of member ID contains “00” "then I want to proceed with the further process to scrap the data.

If the last two digits of Member ID’s contains apart from “00” value then I want to replace by the last two number by"00", after replacing the last two digits with “00” then I need to proceed for the scrapping part.

How to do that please help me to resolve the same.

@Palaniyappan
@ppr
@Yoichi
@nikhil.girish
@ushu
@geetishree.rao
@Nithinkrishna
@rahulsharma

Thanks in advance

1 Like

Hey @HeartCatcher

Iterate the list & do the string manipulation,

Assuming str is your string

new String(str.Take(str.Length - 2).ToArray) + "00"

Proceed for scraping !

Hope this helps

Thanks
#nK

1 Like

@HeartCatcher Use the below exp to check the 00’s exists at the end

System.Text.RegularExpressions.Regex.IsMatch(InputStr,"00$")

It retruns bool valure then you can use other exp to replace

System.Text.RegularExpressions.Regex.Replace(InputStr, "\d{2}$", "00")

Please find workflow below

Example.zip (2.5 KB)

1 Like

Hi @HeartCatcher
You can use Assign activity

MemberID = Left(MemberID,7) + "00"

It will replace the last 2 digits forcibly.

1 Like

Id number is dynamic it not always contain 9 digits only ,sometime it contains 8,7 etc

@HeartCatcher It will always looks for last two numbers no matter of length

1 Like

@HeartCatcher

1 Like

Hi @HeartCatcher ,

I hope below code would help you

arrMembers = {"123456709","234156808","342516707"}

lstMembers = arrMembers.ToList().Select(Function(a) a.Substring(0, a.Length - 2) + "00")

then use foreach to loop “lstMembers” variable

1 Like

@ushu

Thanks.

1 Like

Hi @HeartCatcher
Try this

MemberID = 
System.Text.RegularExpressions.Regex.Matches(MemberID,"(.+)..$")(0).Groups(1).Value+"00"

@HeartCatcher
Find an approach working on any digit length, looking for the last 2 digits and doing the replacements when needed


\b(\d+)(\d[1-9]|[1-9]\d)\b

1 Like

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