How to find the multiple different extension present in the string?

Hi,

I need to find out the extension count present in the string variable
For Example: I have string variable strvalue = “blocked_23.06.013.NWT.txtP_37-PCCl.pdf”

Above strvalue is having 2 extension (i.e .txt & .pdf) Like that different kind of extension will be in the variable while looping.

How to get the count of the extension present in the variable.

Can someone guide me please. Thanks in advance.

Regards,
Jamuna T

@jamunatj

If you know possible extensions then we can count…else as the string is combined its difficult

Cheers

1 Like

Thanks for the reply @Anil_G .

Kindly let me know, How to do with possible extensions which i .know.

Regards,
Jamuna T

@jamunatj

You can do like this

Str.ToLower.Split({".pdf",".txt"},StringSplitOptions.None).Count - 1

You can add more extensions as you know and str is the string to check

Hope this helps

Cheers

Hi @jamunatj ,

You could use regular expression.
system.Text.RegularExpressions.Regex.Matches(inString,“.[A-Za-z]{3}”).Count