Difference between revisions of "Documentation/How Tos/Calc: SEARCH function"
From Apache OpenOffice Wiki
< Documentation | How Tos
Javier Lopez (talk | contribs) |
m |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{DISPLAYTITLE:SEARCH function}} |
− | + | {{Documentation/CalcFunc TextTOC | |
− | + | |ShowPrevNext=block | |
− | + | |PrevPage=Documentation/How_Tos/Calc:_ROMAN_function | |
− | | | + | |NextPage=Documentation/How_Tos/Calc:_SUBSTITUTE_function |
− | + | }}__NOTOC__ | |
− | | | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | }} | ||
== SEARCH == | == SEARCH == | ||
Line 50: | Line 21: | ||
: A failed search gives the <tt>'''#VALUE!'''</tt> error. | : A failed search gives the <tt>'''#VALUE!'''</tt> error. | ||
− | : In | + | : In {{menu|Tools|Options|OpenOffice Calc|Calculate}} the setting for <i>Search criteria = and <>must apply to whole cells</i> has no effect. |
=== Example: === | === Example: === | ||
Line 71: | Line 42: | ||
:: <tt>'''IF( ISNUMBER( SEARCH("xyz","abcdef",1) ) , "Substring Present", "ERR: Missing Substring" )'''</tt>. | :: <tt>'''IF( ISNUMBER( SEARCH("xyz","abcdef",1) ) , "Substring Present", "ERR: Missing Substring" )'''</tt>. | ||
::: returns <tt>'''"ERR: Missing Substring"'''</tt> (... allowing the IF() to function, and not propagating the error from the SEARCH() function. | ::: returns <tt>'''"ERR: Missing Substring"'''</tt> (... allowing the IF() to function, and not propagating the error from the SEARCH() function. | ||
− | :: NOTE: In practice, it may be more maintainable to use ISNUMBER() to avoid negative logic, and it is more | + | :: NOTE: In practice, it may be more maintainable to use ISNUMBER() to avoid negative logic, and it is more indicative of the evaluation desired: if the substring has a position, then ISNUMBER() is TRUE, else ISNUMBER() is FALSE. |
− | {{ | + | |
+ | |||
+ | {{SeeAlso|EN| | ||
* [[Documentation/How_Tos/Calc: REPLACE function|REPLACE]] | * [[Documentation/How_Tos/Calc: REPLACE function|REPLACE]] | ||
* [[Documentation/How_Tos/Calc: FIND function|FIND]] | * [[Documentation/How_Tos/Calc: FIND function|FIND]] |
Latest revision as of 15:39, 2 February 2024
< {{#switch:Previous Page | Previous Section = Previous Section | Next Section = Next Section | Previous Page = Previous Page | Next Page = Next Page | }} | {{#switch:Next Page | Previous Section = Previous Section | Next Section = Next Section | Previous Page = Previous Page | Next Page = Next Page | }} > |
SEARCH
Returns the position of a string of text within another string.
Syntax:
SEARCH(findtext; texttosearch; startposition)
- returns the character position of the first occurrence of findtext within texttosearch.
- startposition (optional) is the position from which the search starts.
- The search is not case-sensitive.
- The search will use regular expressions, if they are enabled (Tools - Options - OpenOffice.org Calc - Calculate).
- A failed search gives the #VALUE! error.
- In {{#if: Tools |Tools}}{{#if: Options | → Options}}{{#if: OpenOffice Calc | → OpenOffice Calc}}{{#if: Calculate | → Calculate}}{{#if: | → {{{5}}}}}{{#if: | → {{{6}}}}}{{#if: | → {{{7}}}}}{{#if: | → {{{8}}}}}{{#if: | → {{{9}}}}}{{#if: | → {{{10}}}}} the setting for Search criteria = and <>must apply to whole cells has no effect.
Example:
SEARCH("yo"; "Yoyo")
- returns 1. The search is case-insensitive.
SEARCH("cho"; "choochoo"; 2)
- returns 5.
SEARCH("t.n"; "often")
- returns 3, if regular expressions are enabled. The "." stands for any single character in a regular expression, so "t.n" matches "ten".
SEARCH("xyz","abcdef",1)
- returns #VALUE!.
- NOTE: This is an error condition, which must be 'handled' if used as the argument to another function.
- IF( SEARCH("xyz","abcdef",1) , "Substring Present", "ERR: Missing Substring" )
- returns #VALUE! which is not very useful, therefore we could use either ISERROR() or ISNUMBER() for example:
- IF( ISERROR( SEARCH("xyz","abcdef",1) ) , "ERR: Missing Substring", "Substring Present" ).
- returns "ERR: Missing Substring" (... allowing the IF() to function, and not propagating the error from the SEARCH() function.
- IF( ISNUMBER( SEARCH("xyz","abcdef",1) ) , "Substring Present", "ERR: Missing Substring" ).
- returns "ERR: Missing Substring" (... allowing the IF() to function, and not propagating the error from the SEARCH() function.
- NOTE: In practice, it may be more maintainable to use ISNUMBER() to avoid negative logic, and it is more indicative of the evaluation desired: if the substring has a position, then ISNUMBER() is TRUE, else ISNUMBER() is FALSE.
{{#switch:EN
| RU = Смотрите также:
| UA = Дивіться також:
| EN = See Also
| PT = Ver também
| #default = See Also
}}