Extracting output from array of strings

Hi All,
I have an array of strings.
arrStrings = {“99M”,“99MY”,“Page2_99MY”,“Page2_99M”}
How to extract subarray with all 99M.

@harshit_gupta,

You can use this LINQ

arrFiltered = arrStrings.Where(Function(s) s.Contains("99M")).ToArray()

I have tried but it is also including all 99MY too

@harshit_gupta ,

Ok if your 99M would be at the end then you can use this one.

arrFiltered = arrStrings.Where(Function(s) s.EndsWith("99M")).ToArray()

Hi @harshit_gupta

Can you try this

subArray = arrStrings.Where(Function(s) s.Equals("99M") OrElse s.StartsWith("99M_") OrElse s.EndsWith("_99M")).ToArray()

Regards,

@harshit_gupta

Please try using regex which would check only for 99M

Arr.Where(function(x) System.Text.RegularExpressions.Regex.IsMatch(x,"\b99M\b")).ToArray

Cheers