Substring last 8 characters

Hi,

I have a variable text which can look like this: abc_defg_hijklm_20180810.zip. The letters can vary and sometimes there can be more underscores with text in the text.

I need to extract the ‘20180810’ out of the string.
I started with varnameNew = varnameOld.split(“.”c)(0) to get the part before the .zip. But now I need to know how to extract the last 8 characters.

Thanks.

4 Likes

@yannip

You can use regex to achieve what you want.

This regex will get your string

output_string = system.Text.RegularExpressions.Regex.Match("abc_defg_hijklm_20180810.zip","(?<=_)(\d{8})(?=.zip)").Value

Regards,
Ranjith

3 Likes

Thanks for your response @ranjith.
Do I put this in an assign activity?
Because it is not giving me any result for the moment. (blank result in the output panel)

str.Substring(str.Length -8)

5 Likes

Thanks! This was what I was looking for!

1 Like

@yannip

Yes you have to use assign activity.

Regards,
Ranjith.

1 Like

@yannip And if you want to fetch only number from your string then used blow regex
System.Text.RegularExpressions.Regex.Replace(str,“[A-Z a-z]”,“”)
str is my variable where i stored my string .

1 Like