Difference between revisions of "FindInText"

Line 4: Line 4:
 
= FindInText( substr, text'', start, caseInsensitive'' ) =
 
= FindInText( substr, text'', start, caseInsensitive'' ) =
  
Returns the position of the first occurrence of ''substr'' in ''text''.  If ''substr'' does not occur in ''text'', returns 0.  The optional third parameter, ''start'', specifies the position to start searching at.  You can specify the fourth parameter, ''caseInsensitive'', as True to signify that upper and lower variants of the same characters match.
+
Returns the position of the first occurrence of «substr» in «text».  If «substr» does not occur in «text», returns 0.  The optional third parameter, «start», specifies the position to start searching at.  You can specify the fourth parameter, «caseInsensitive», as ''True'' to signify that upper and lower variants of the same characters match.
  
 
= Library =
 
= Library =
Line 12: Line 12:
 
= Examples =
 
= Examples =
  
:[[FindInText]]("Now is not the time","is") → 5
+
:[[FindInText]]("is","Now is not the time") → 5
:[[FindInText]]("Now is not the time","i") → 5
+
:[[FindInText]]("i","Now is not the time") → 5
:[[FindInText]]("Now is not the time","i",6) → 17
+
:[[FindInText]]("i","Now is not the time","i") → 17
:[[FindInText]]("Now is not the time","now") → 0
+
:[[FindInText]]("now","Now is not the time") → 0
:[[FindInText]]("Now is not the time","no") → 8
+
:[[FindInText]]("no","Now is not the time") → 8
:[[FindInText]]("Now is not the time","no",caseInsensitive:True) → 1
+
:[[FindInText]]("no","Now is not the time",caseInsensitive:True) → 1
 +
 
 +
= Regular Expressions =
 +
 
 +
''New to [[What's new in Analytica 4.2?|Analytica 4.2]]''
 +
 
 +
When the optional parameter «re» is set to ''True'', «substr» is interpreted as a [[regular expression]].  For example, the following find the location of the first vowel:
 +
 
 +
:[[FindInText]]("[aeiou]","Now is not the time",re:True,caseInsensitive:True) → 2
 +
 
 +
When matching a pattern, you may want information other than just the starting position.  The optional parameter «return» specifies what information about the match is desired.  «Return» can be specified as any of the following (or an array of any of these):
 +
* 'P' (or 'Position'): The position in the subject ''text'' where the matched pattern was found, or zero if not found.
 +
* 'L' (or 'Length'): The length of the match in the subject text.
 +
* 'S' (or 'SubPattern'): The subtext matched by the pattern
 +
* '#' (or '#SubPatterns'): The number of subpatterns in the regular expression.
 +
 
 +
Examples:
 +
:[[FindInText]]("[aeiou]","Now is the time for",re:True,return:'S') → 'o'
 +
:[[FindInText]]("\w{4}","Now is the time for",re:True, return:'S') → 'time'
 +
:[[FindInText]]("\w{4}\w*","We the people, in order to...",re:True,return:['S','L','P']) → ['people',6,8]
 +
 
 +
For more details, see [[Regular Expressions]].
  
 
= See Also =
 
= See Also =
  
 +
* [[Regular Expressions]]
 
* [[SelectText]], [[TextReplace]]
 
* [[SelectText]], [[TextReplace]]

Revision as of 17:27, 23 February 2009


FindInText( substr, text, start, caseInsensitive )

Returns the position of the first occurrence of «substr» in «text». If «substr» does not occur in «text», returns 0. The optional third parameter, «start», specifies the position to start searching at. You can specify the fourth parameter, «caseInsensitive», as True to signify that upper and lower variants of the same characters match.

Library

Text Functions

Examples

FindInText("is","Now is not the time") → 5
FindInText("i","Now is not the time") → 5
FindInText("i","Now is not the time","i") → 17
FindInText("now","Now is not the time") → 0
FindInText("no","Now is not the time") → 8
FindInText("no","Now is not the time",caseInsensitive:True) → 1

Regular Expressions

New to Analytica 4.2

When the optional parameter «re» is set to True, «substr» is interpreted as a regular expression. For example, the following find the location of the first vowel:

FindInText("[aeiou]","Now is not the time",re:True,caseInsensitive:True) → 2

When matching a pattern, you may want information other than just the starting position. The optional parameter «return» specifies what information about the match is desired. «Return» can be specified as any of the following (or an array of any of these):

  • 'P' (or 'Position'): The position in the subject text where the matched pattern was found, or zero if not found.
  • 'L' (or 'Length'): The length of the match in the subject text.
  • 'S' (or 'SubPattern'): The subtext matched by the pattern
  • '#' (or '#SubPatterns'): The number of subpatterns in the regular expression.

Examples:

FindInText("[aeiou]","Now is the time for",re:True,return:'S') → 'o'
FindInText("\w{4}","Now is the time for",re:True, return:'S') → 'time'
FindInText("\w{4}\w*","We the people, in order to...",re:True,return:['S','L','P']) → ['people',6,8]

For more details, see Regular Expressions.

See Also

Comments


You are not allowed to post comments.