Difference between revisions of "Documentation/How Tos/Calc: FIND function"
From Apache OpenOffice Wiki
< Documentation | How Tos
Javier Lopez (talk | contribs) |
GreatBigBore (talk | contribs) (Indicated that the function does not use regex; referred to SEARCH() for case-insensitive and regex searching; added note for =/<> setting, to be consistent with SEARCH() documentation) |
||
Line 43: | Line 43: | ||
: <tt>'''startposition'''</tt> (optional) is the position from which the search starts. | : <tt>'''startposition'''</tt> (optional) is the position from which the search starts. | ||
− | : The search is case-sensitive. | + | : The search is case-sensitive. For case-insensitive search, see '''SEARCH()''' |
+ | |||
+ | : The search will '''not''' use regular expressions. For searching with regular expressions, see '''SEARCH()''' | ||
: A failed search gives the <tt>'''#VALUE!'''</tt> error. | : A failed search gives the <tt>'''#VALUE!'''</tt> error. | ||
+ | |||
+ | : In '''Tools - Options - OpenOffice.org Calc - Calculate''' the setting for <i>Search criteria = and <> must apply to whole cells</i> has no effect. | ||
=== Example: === | === Example: === |
Revision as of 15:21, 18 July 2013
CALC FUNCTIONS
< {{#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 | }} > |
FIND
Returns the position of a string of text within another string.
Syntax:
FIND(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 case-sensitive. For case-insensitive search, see SEARCH()
- The search will not use regular expressions. For searching with regular expressions, see SEARCH()
- A failed search gives the #VALUE! error.
- In Tools - Options - OpenOffice.org Calc - Calculate the setting for Search criteria = and <> must apply to whole cells has no effect.
Example:
FIND("yo"; "Yoyo")
- returns 3.
FIND("cho"; "choochoo"; 2)
- returns 5.
FIND("xyz","abcdef",1)
- returns #VALUE!.
- NOTE: This is an error condition, which must be 'handled' if used as the argument to another function.
- IF( FIND("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( FIND("xyz","abcdef",1) ) , "ERR: Missing Substring", "Substring Present" ).
- returns "ERR: Missing Substring" (... allowing the IF() to function, and not propagating the error from the FIND() function.
- IF( ISNUMBER( FIND("xyz","abcdef",1) ) , "Substring Present", "ERR: Missing Substring" ).
- returns "ERR: Missing Substring" (... allowing the IF() to function, and not propagating the error from the FIND() function.
- NOTE: In practice, it may be more maintainable to use ISNUMBER() to avoid negative logic, and it is more indicitive of the evaluation desired: if the substring has a position, then ISNUMBER() is TRUE, else ISNUMBER() is FALSE.