Get the location of substring in a string
=SEARCH(find_text, within_text, [start_num])
| Parameter | Description |
|---|---|
find_text |
The substring to find. |
within_text |
The text to search within. |
start_num |
[optional] Starting position. Optional, defaults to 1. |
The basic syntax of the SEARCH function looks like this
SEARCH(find_text,within_text,[start_num])
The SEARCH function is designed to look inside a text string for a specific substring. When SEARCH locates the substring, it returns the position of t
=SEARCH("p","apple") // returns 2
=SEARCH("z","apple") // returns #VALUE!
=SEARCH("apple","Pineapple") // returns 5
Note that text values entered directly into SEARCH must be enclosed in double quotes (""). Unlike the FIND function, the SEARCH function is not case-s
=SEARCH("a","Apple") // returns 1
=SEARCH("A","Apple") // returns 1
=SEARCH("Apple","Pineapple") // returns 5
By default, the SEARCH function returns a number when a search string is found and a #VALUE! error when not. This is inconvenient in cases where you s
=ISNUMBER(SEARCH("p","apple")) // returns TRUE
=ISNUMBER(SEARCH("z","apple")) // returns FALSE
Once you have a TRUE or FALSE result, you can combine the SEARCH function with the IF function to create "if cell contains" logic. The generic pattern
=IF(ISNUMBER(SEARCH(substring,A1)), "Yes", "No")
The formula in C5, copied down, is:
=IF(ISNUMBER(SEARCH("abc",B5)),"x","")