substring and the indexOf method

前端 未结 2 1526
太阳男子
太阳男子 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: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.

提交回复
热议问题