SEARCH(find_text,within_text,start_num)
SEARCHB(find_text,within_text,start_byte)
Definition. The SEARCH() function returns the first occurrence at which a string is found. The search starts at the position indicated by the start_num argument. The function is not case-sensitive.
The SEARCHB() function returns the number of bytes of the characters. This function is used for double-byte strings.
Arguments
find_text (required). The string you are searching for
within_text (required). The text in which to search for find_text
start_num/start_byte (optional). The starting character from which to begin the search
Background. If you edit text, you often need to know the position of a certain character or string within the text—for example, when you want to remove or replace the character. To do this, you use the SEARCH() or FIND()function.
Unlike FIND() and FINDB(), the SEARCH() and SEARCHB() functions are not case-sensitive and allow the wildcard characters * and ?.
The SEARCH() function returns the character number at the start of the located text. The search text can include the wildcard characters ? and *. The question mark (?) stands for a character, and the asterisk (*) stands for a string. If you enter ? or *, the search string must be preceded by a tilde (~).
Use start_num to begin the search a specified number of characters into the string. For example, if you want to know the position of the first e after the initial code in the string XLS2003_FormatCellProtection, use 9 for start_num to skip the first part of the string. SEARCH() starts at the ninth character and returns the sixteenth character.
Note the following when working with this function:
If you search for an empty string (“”), the SEARCH() function returns the value 1
or the value specified in start_num.
SEARCH() returns the #VALUE!
error if it cannot find the string.
If the start_num argument is not specified, the function uses the default value 1.
SEARCH() returns the #VALUE!
error if start_num is less than or equal to 0.
SEARCH() returns the #VALUE!
error if start_num is greater than the length of the string.
Example. If you want to know whether the text in a column contains letters or numbers enclosed by square brackets, you can use a calculated column with a wildcard character search, as shown in Figure 8-11. The formula
=SEARCH(C25,D25)
returns position 5
. The search looks for a string of any characters enclosed in square brackets. The string [small] starts at position 5 in the search string.
Here are some further examples:
=SEARCH("r","intercontinental flight",1)
returns
5
.
=SEARCH("R""intercontinental flight",1)
returns
5
.
=SEARCH("t""intercontinental flight",1)
returns
3
.
=SEARCH("I""intercontinental flight",1)
returns
1
.
=SEARCH("i""intercontinental flight",1)
returns
1
.
=SEARCH("i""intercontinental flight",2)
returns
10
.