VB.NET function to check starting substring

I am looking for VB.NET function to check if a string is starting with anything between 500 to 599
 

Example strings
   523 Doc1
   Doc1
   5002Doc2
   Document523SubDoc
   522-Doc3

The valid strings from the above are
   523 Doc1
   522-Doc3
Sam OZAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongSoftware Team LeadCommented:
try like:

Dim yourString() As String = {"523 Doc1", "Doc1", "5002Doc2", "Document523SubDoc", "522-Doc3"}
        Dim resultString() As String
        Dim cnt As Integer = 0
        Dim num As Integer

        For Each value As String In yourString
            Dim startNo As String = Regex.Match(value, "^\d+").Value
            Integer.TryParse(startNo, num)

            If num >= 500 And num <= 599 Then
                ReDim Preserve resultString(cnt)
                resultString(cnt) = value
                cnt = cnt + 1
            End If
        Next

        MsgBox(String.Join(vbCrLf, resultString))

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sam OZAuthor Commented:
Thanks . But I don't need this to come as an array . At one time only one string is taken ( For example Doc1).  The function just need to check the rule of 5xx and return true or false
I hope the StartNo variable is god enough
Ryan ChongSoftware Team LeadCommented:
yup, similar concept applied for one string, hence use the part mentioned below should be good enough:

Dim startNo As String = Regex.Match(value, "^\d+").Value
            Integer.TryParse(startNo, num)

Open in new window


and then refer to the value of num
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.