Difference between revisions of "Documentation/How Tos/Calc: FIND function"

From Apache OpenOffice Wiki
Jump to: navigation, search
(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)
m
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Documentation/MasterTOC
+
{{DISPLAYTITLE:FIND function}}
|bookid=1234'''
+
{{Documentation/CalcFunc TextTOC
|booktitle=<div style="padding: 8px; font-size: 140%; font-weight: bold; background-color: #9BC0F5;">CALC FUNCTIONS</div>
+
|ShowPrevNext=block
|ShowParttitle=block|parttitle=[[Documentation/How_Tos/Calc:_Text_functions|<div style="font-size: 140%;">Text Functions]]
+
|PrevPage=Documentation/How_Tos/Calc:_EXACT_function
|ShowNextPage=block|NextPage=Documentation/How_Tos/Calc:_FIXED_function
+
|NextPage=Documentation/How_Tos/Calc:_FIXED_function
|ShowPrevPage=block|PrevPage=Documentation/How_Tos/Calc:_EXACT_function
+
}}__NOTOC__
|ShowPrevPart=block|PrevPart=Documentation/How_Tos/Calc:_Statistical_functions
+
|ShowNextPart=block|NextPart=Documentation/Reference/Calc_functions
+
|toccontent= <div style="padding: 4px; font-size: 130%; font-weight: hidden; background-color:#DCE9FC;">FUNCTIONS</div>
+
  
* [[Documentation/How_Tos/Calc:_BASE_function|<div style="font-size: 120%;">Base]]
 
* [[Documentation/How_Tos/Calc:_CHAR_function|<div style="font-size: 120%;">Char]]
 
* [[Documentation/How_Tos/Calc:_CLEAN_function|<div style="font-size: 120%;">Clean]]
 
* [[Documentation/How_Tos/Calc:_CODE_function|<div style="font-size: 120%;">Code]]
 
* [[Documentation/How_Tos/Calc:_CONCATENATE_function|<div style="font-size: 120%;">Concatenate]]
 
* [[Documentation/How_Tos/Calc:_DOLLAR_function|<div style="font-size: 120%;">Dollar]]
 
* [[Documentation/How_Tos/Calc:_EXACT_function|<div style="font-size: 120%;">Exact]]
 
* [[Documentation/How_Tos/Calc:_FIND_function|<div style="font-size: 120%; border-style: double; border-color:#778899;">Find]]
 
* [[Documentation/How_Tos/Calc:_FIXED_function|<div style="font-size: 120%;">Fixed]]
 
* [[Documentation/How_Tos/Calc:_LEFT_function|<div style="font-size: 120%;">Left]]
 
* [[Documentation/How_Tos/Calc:_LEN_function|<div style="font-size: 120%;">Len]]
 
* [[Documentation/How_Tos/Calc:_LOWER_function|<div style="font-size: 120%;">Lower]]
 
* [[Documentation/How_Tos/Calc:_MID_function|<div style="font-size: 120%;">Mid]]
 
* [[Documentation/How_Tos/Calc:_PROPER_function|<div style="font-size: 120%;">Proper]]
 
* [[Documentation/How_Tos/Calc:_REPLACE_function|<div style="font-size: 120%;">Replace]]
 
* [[Documentation/How_Tos/Calc:_REPT_function|<div style="font-size: 120%;">Rept]]
 
* [[Documentation/How_Tos/Calc:_RIGHT_function|<div style="font-size: 120%;">Right]]
 
* [[Documentation/How_Tos/Calc:_SEARCH_function|<div style="font-size: 120%;">Search]]
 
* [[Documentation/How_Tos/Calc:_SUBSTITUTE_function|<div style="font-size: 120%;">Substitute]]
 
* [[Documentation/How_Tos/Calc:_T_function|<div style="font-size: 120%;">T]]
 
* [[Documentation/How_Tos/Calc:_TEXT_function|<div style="font-size: 120%;">Text]]
 
* [[Documentation/How_Tos/Calc:_TRIM_function|<div style="font-size: 120%;">Trim]]
 
* [[Documentation/How_Tos/Calc:_UPPER_function|<div style="font-size: 120%;">Upper]]
 
* [[Documentation/How_Tos/Calc:_VALUE_function|<div style="font-size: 120%;">Value]]
 
}}__TOC__
 
 
== FIND ==
 
== FIND ==
 
Returns the position of a string of text within another string.  
 
Returns the position of a string of text within another string.  
Line 43: Line 15:
 
: <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. For case-insensitive search, see '''SEARCH()'''
+
: 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()'''
+
: 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.
Line 53: Line 25:
 
=== Example: ===
 
=== Example: ===
 
<tt>'''FIND("yo"; "Yoyo")'''</tt>
 
<tt>'''FIND("yo"; "Yoyo")'''</tt>
: returns <tt>'''3'''</tt>.
+
: returns <tt>'''3'''</tt>. The search is case-sensitive.
  
 
<tt>'''FIND("cho"; "choochoo"; 2)'''</tt>
 
<tt>'''FIND("cho"; "choochoo"; 2)'''</tt>
Line 67: Line 39:
 
:: <tt>'''IF( ISNUMBER( FIND("xyz","abcdef",1) ) , "Substring Present", "ERR: Missing Substring" )'''</tt>.
 
:: <tt>'''IF( ISNUMBER( FIND("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 FIND() function.
 
::: returns <tt>'''"ERR: Missing Substring"'''</tt> (... 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.
+
:: 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.
  
{{Documentation/SeeAlso|
+
{{SeeAlso|EN|
 
* [[Documentation/How_Tos/Calc: REPLACE function|REPLACE]]
 
* [[Documentation/How_Tos/Calc: REPLACE function|REPLACE]]
 
* [[Documentation/How_Tos/Calc: SEARCH function|SEARCH]]
 
* [[Documentation/How_Tos/Calc: SEARCH function|SEARCH]]

Latest revision as of 15:29, 2 February 2024



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. The search is case-sensitive.

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 indicative of the evaluation desired: if the substring has a position, then ISNUMBER() is TRUE, else ISNUMBER() is FALSE.



See Also
Retrieved from "https://wiki.openoffice.org/w/index.php?title=Documentation/How_Tos/Calc:_FIND_function&oldid=260103"
Views
Personal tools
Navigation
Tools