Searchb
Syntax:¶
SEARCHB(find_text, within_text, [start_num])
- find_text: The text you want to find. This can be a single character or a string. Wildcard characters
*and?are supported. - within_text: The text in which you want to search for the
find_text. - start_num (optional): The byte position in
within_textat which to start the search. The default is 1, which starts at the first byte.
Description:¶
The SEARCHB function in Excel locates one text string within another and returns the starting position measured in
bytes rather than characters. This distinction is important when working with double-byte character set (DBCS)
languages such as Japanese, Chinese, and Korean, where a single character can occupy two bytes. In single-byte
character set (SBCS) languages such as English, SEARCHB behaves identically to the SEARCH function because each
character is one byte.
Unlike the FINDB function, SEARCHB is case-insensitive — it does not distinguish between uppercase and lowercase
letters. It also supports wildcard characters (* to match any number of characters and ? to match a single
character). If you need a case-sensitive byte-based search, use the FINDB function instead.
Examples:¶
=SEARCHB("World", "Hello World")- Returns:
7(In an SBCS environment, "World" starts at byte 7, the same position as the character position.)
- Returns:
=SEARCHB("cat", "Concatenation")- Returns:
4(The case-insensitive search finds "cat" starting at byte 4 in "Concatenation".)
- Returns:
=SEARCHB("CAT", "Concatenation")- Returns:
4(The search is case-insensitive; "CAT" matches "cat" within "Concatenation" at byte 4.)
- Returns:
=SEARCHB("B", "AABBCC", 3)- Returns:
3(Starting the search at byte position 3, the first "B" is found at byte 3.)
- Returns:
=SEARCHB("c*n", "Concatenation")- Returns:
4(The wildcard*matches any number of characters between "c" and "n".)
- Returns:
Notes:¶
- The
SEARCHBfunction is case-insensitive. UseFINDBif you need a case-sensitive byte-based search. - If
find_textis not found withinwithin_text, the function returns a#VALUE!error. You can wrapSEARCHBin anIFERRORfunction to handle this gracefully. - In SBCS languages (e.g., English),
SEARCHBreturns the same results asSEARCHbecause each character equals one byte. The difference only becomes apparent in DBCS languages where characters may occupy two bytes. - The
start_numargument counts bytes, not characters. When working with DBCS text, be mindful that a double-byte character occupies positions for two bytes. SEARCHBsupports wildcard characters: use*to match any sequence of characters and?to match any single character. For exact-match byte-position searches without wildcards, useFINDB.- For character-based position searching (rather than byte-based), use the
SEARCHfunction. - The
SEARCHBfunction is equivalent toSEARCHin Excel when the default language setting is a single-byte character set language. In DBCS language environments,SEARCHBcounts each double-byte character as 2 bytes.