InStr Samples

Tuesday, November 19, 2002 22:53:37
home

InStr is a great little function that's very useful. Basically, it searches for the existence (and location from the left) of a particular character within a string. It's really useful for parcing a string apart--say, deciphering a person's first and last name from a bit of data which has their full name combined into one data bit.

Larry Harrison = LH Example

This was used as the control source for a text box which contained a person's name (first and last, with a space in-between). It would, say, return LH if the name was Larry Harrison. The field's name was "contact_name." The syntax:

=Left([contact_name],1) & Mid([contact_name],InStr([contact_name]," ")+1,1)

Other Examples (Visual Basic and Textbox "Control Source" Examples)


FirstPos = InStr([IP],".")
(FirstPos is a numeric variable)

This finds the position of the . character within the IP variable and stores the value in FirstPos.

InStr(InStr(MyString, "=") + 1, MyString, "=")

This says, "Find the first '=' starting at the character after the first '=' in the string." (i.e. the second '=').