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 IndexOf method on the address.
I understand that IndexOf returns the position of a character and the number of characters.
What would be the purpose of using the IndexOf method on the address in this instance?
I don’t understand what I would be searching for when the user types in it’s address that’s going to be numbers and string characters.
I think I understand what the IndexOf method does, somewhat, but why and what would I use it to achieve?
You’d typically use
IndexOfto –See if a string contained something
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
IndexOfwill return -1 if it does not find the string your searching for, so your code will have to handle that eventuality.