Extracting the Specific character from string

There will be String variable which consists of some value so, I need to extract the 6th character from that string variable and need to check the 6th character is not empty and that has to be numeric. any suggestions…

Hi,

Hope the following helps you.

yourString(5)

need to check the 6th character is not empty and that has to be numeric.

System.Text.RegularExpressions.Regex.IsMatch(yourString,"^[\s\S]{5}\d")

Regards,

Thank you for your response. But
If I use mystring(5), this won’t work on all cases what happens if my string doesn’t contains 6 characters it will throw an Index bound out of range exception.

Basically, In mystring i am not sure how many character it contains. Irrespective of number of characters In Mystring variable,
I need to check the 6th character is not null and that has to be numeric… needed some suggestion this

Hi,

Alright. The following will work (no error) even if length is 5 or less.

Check if numeric

System.Text.RegularExpressions.Regex.IsMatch(yourString,"^[\s\S]{5}\d")

6th character

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=^[\s\S]{5})[\s\S]").Value

Regards,

1 Like

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