0

I have alphanumeric strings like S00125701. How do I find numbers in between?

Case H00125701 To H00125859
    Label1.Text = "Box # 110"
4
  • I have no idea what you're asking. You want to strip the first letter off of the string and get only the number? Or something else? And then what? Commented Dec 24, 2010 at 8:00
  • Agreeing with Cody. If you strip the letter off and subtract the remaining two numbers, the answer is not 110. Commented Dec 24, 2010 at 12:26
  • @dbasnett - I don't think the 110 is supposed to be a subtraction, I think it is simply a label to be used for that particular range in the SELECT CASE. I may be wrong of course! Commented Dec 24, 2010 at 12:39
  • 1
    In order for us to help, you need to better describe your problem. Commented Dec 24, 2010 at 15:29

1 Answer 1

3

You can Select Case directly on the string:

 Select Case string
        Case "H00125701" To "H00125859"
            Label1.Text = "Box # 110"
    End Select

If your problem is that your input string starts with S but you have to test against strings which begin with H then a Replace will work:

 Select Case string.Replace("S", "H")
        Case "H00125701" To "H00125859"
            Label1.Text = "Box # 110"
    End Select

If your problem is that your input string could start with any letter but you have to test against strings which begin with H (or any other letter for that matter) and there will only ever be a single letter then a Substring and Convert will work:

 Select Case Convert.ToInt32(string.Substring(1))
        Case 125701 To 125859
            Label1.Text = "Box # 110"
    End Select
Sign up to request clarification or add additional context in comments.

1 Comment

My god, I had no idea this case notation existed. Beautiful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.