substring and the indexOf method

前端 未结 2 1498
太阳男子
太阳男子 2021-01-14 10:03

My assignment in Visual Basic 2010 is to build a order form that has two text boxes, one for the name and the other for the address.

And we\'re suppose to use the <

相关标签:
2条回答
  • 2021-01-14 10:23

    Since this is a homework question, I will answer with a question or several:

    • How would you normally enter a full address into a text box?
    • How would each part of the address be distinguishable from another?
    • Once you figure out how this can be done, think about IndexOf again.
    0 讨论(0)
  • 2021-01-14 10:31

    You'd typically use IndexOf to -

    See if a string contained something

    If someString.IndexOf("Avenue") > - 1 Then
       'do something
    End If
    

    Get the start position of a value in a string , this could then be used to extract part of the string. e.g. someString.Substring(someString.IndexOf("@"),10) would get then next ten characters starting from where the "@" character was found in your string.

    Bear in mind you'll always need to handle scenarios where IndexOf will return -1 if it does not find the string your searching for, so your code will have to handle that eventuality.

    0 讨论(0)
提交回复
热议问题