Text functions
SEARCHB
Matches all 6 recorded answers
Recorded: 6 workbook cells. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | SEARCHB |
| Bulgarian | SEARCHB |
| Czech | SEARCHB |
| Danish | SØGB |
| German | SUCHENB |
| Greek | SEARCHB |
| English (Australia) | SEARCHB |
| English (United Kingdom) | SEARCHB |
| English (United States) | SEARCHB |
| Spanish | HALLARB |
| Estonian | SEARCHB |
| Finnish | KÄY.LÄPIB |
| French | CHERCHERB |
| Hebrew | SEARCHB |
| Croatian | SEARCHB |
| Hungarian | SZÖVEG.KERES2 |
| Indonesian | SEARCHB |
| Italian | CERCA.B |
| Japanese | SEARCHB |
| Korean | SEARCHB |
| Lithuanian | SEARCHB |
| Latvian | SEARCHB |
| Norwegian | SØKB |
| Dutch | VIND.SPEC.B |
| Polish | SZUKAJ.TEKST.B |
| Portuguese (Brazil) | LOCALIZARB |
| Portuguese (Portugal) | PROCURARB |
| Romanian | SEARCHB |
| Russian | ПОИСКБ |
| Slovak | SEARCHB |
| Slovenian | SEARCHB |
| Serbian (Latin) | SEARCHB |
| Swedish | SÖKB |
| Thai | SEARCHB |
| Turkish | ARAB |
| Ukrainian | SEARCHB |
| Vietnamese | SEARCHB |
| Chinese (Simplified) | SEARCHB |
| Chinese (Hong Kong) | SEARCHB |
| Chinese (Traditional) | SEARCHB |
Names from Microsoft's support site.
What it does
SEARCHB(find_text, within_text, [start_num])
SEARCHB(find_text, within_text, [start_num]) locates find_text inside within_text and
returns the 1-based byte position at which it starts, counted from the beginning of
within_text.
Everything that makes SEARCH what it is carries over unchanged: the match is
not case sensitive, and find_text is a wildcard pattern in which ? matches any
single character, * matches any sequence, and ~ escapes a following ? or *. The B in
the name changes the coordinate system of the answer and the coordinate system of start_num.
It does not change the matching rule.
And the coordinate change itself is conditional. Microsoft's rule for the whole B family:
The B functions count each double-byte character as 2 only when a DBCS language has been enabled for editing and set as the default language. Otherwise they count each character as 1.
So on a non-DBCS-default installation SEARCHB and SEARCH return the same numbers for the
same inputs. On a Japanese-, Chinese- or Korean-default installation they return different
numbers, because the same match sits at a different byte offset than character offset. The
active default language is an unlisted input to this function.
Arguments
| Argument | Meaning | Default |
|---|---|---|
find_text | The pattern to look for. Required. | — |
within_text | The string to look in. Required. | — |
start_num | 1-based byte position at which the scan begins. Optional. | 1 |
start_num is in bytes, which is the argument most likely to be wrong in a formula ported from
SEARCH. A start_num computed from LEN is a character coordinate; feeding it to SEARCHB
is a unit error that produces plausible wrong answers rather than an error value. LENB is
the function that produces the right coordinates.
Try it
Quirks
SEARCHB versus FINDB
The same two-axis distinction as the character pair, restated because it is exactly as confusable at the byte level:
SEARCHB | FINDB | |
|---|---|---|
| Case | not case sensitive | case sensitive |
find_text is | a wildcard pattern (?, *, ~) | a literal string |
| Returns | byte position | byte position |
| Character twin | SEARCH | FIND |
Choosing SEARCHB over FINDB for the case-insensitivity and then passing a find_text that
contains a literal * is the same trap it is on the character functions, and it is no easier
to spot here.
Result and edge cases
Returns Number — a 1-based byte position.
The behaviours Microsoft documents for SEARCH are stated on the same page for SEARCHB:
find_text not found is #VALUE!, and a start_num outside the valid range is #VALUE! —
with the range measured in bytes here.
The distinctively SEARCHB questions, none of which the documentation answers:
- Does
start_numhave to fall on a character boundary? An oddstart_numinside a double-byte character is reachable by ordinary arithmetic and is undefined here. - Does
?match one byte or one character? Under DBCS these differ, and the wildcard language is documented in terms of characters while the result is measured in bytes. This is the sharpest unresolved question on the page. - Is the returned position always on a character boundary? It should be if matches only begin at character boundaries, but that is an inference from a rule nobody has stated.
Errors
As documented on Microsoft's SEARCH, SEARCHB page:
| Error | Condition |
|---|---|
#VALUE! | find_text is not found in within_text. |
#VALUE! | start_num is not greater than 0, or is greater than the length of within_text — in bytes for SEARCHB. |
Shared coercion errors and error propagation apply as elsewhere. The Handbook has not verified any of this against Excel.
How to implement
Notes for implementers
The function has to hold two coordinate systems at once: the match runs over characters (the
wildcard language is defined in characters) and the answer is reported in bytes. That mapping
has to be built from the same code-page tables LENB uses, or the family will not agree with
itself.
The ?-matches-what question is not an implementation detail to be settled quietly. Pick an
answer, document it, mark it unverified, and make it consistent with whatever MIDB does at
partial-character boundaries.
A SEARCHB test vector without the default editing language recorded is not a test vector.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.
SEARCHB · 1 lines · calc-func/src/catalogue/text_functions.rs on GitHub23 searchb_fn "SEARCHB" (2, 3) [V "find_text", V "within_text", V "start_num"] |s, a, sv| { single_byte(s)?; search(s, a, true) }
Kernels shared with other functions
count_surrogate_pairscatalogue/text_functionssingle_bytecatalogue/text_functionsstartcatalogue/text_functionssearchcatalogue/text_functionstextported/text_kernelstext_from_strported/text_kernelsunit_widthported/text_kernelscharacter_boundaryported/text_kernelsslice_character_countported/text_kernelstruncatedported/text_kernelspositiveported/text_kernelsfold_unitported/text_kernelssearch_units_equalported/text_kernelssearch_pattern_matches_prefixported/text_kernelssearchported/text_kernelspush_singleton_or_originalported/text_kernelspush_lowerported/text_kernelslowerported/text_kernels
Argument and result plumbing
No implementation has been published with a Handbook test suite for this function.
Version differences
No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.
Alternatives
Relationships
- SEARCH — the character-position twin, documented by Microsoft on the same page and published by the Handbook as its own entry.
FINDB— the case-sensitive, literal byte locator. See the comparison above.LENB, MIDB, REPLACEB,LEFTB, RIGHTB — the rest of the B family.SEARCHBis the family's coordinate producer: its output is exactly whatMIDBandREPLACEBexpect asstart_num, and mixing aSEARCHresult into aMIDBcall is the classic unit mismatch.- SUBSTITUTE — there is no
SUBSTITUTEB, and that is not an oversight: by-content substitution never needs byte coordinates. Under DBCS it is usually the safer tool.
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents