This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Programming / String Manipulation  /
StringPosition

  • StringPosition[" string ", " sub "] gives a list of the starting and ending character positions at which " sub " appears as a substring of " string ".
  • StringPosition[" string ", " sub ", k ] includes only the first k occurrences of " sub ".
  • StringPosition[" string ", " ", " ", ... ] gives positions of all the " ".
  • Example: StringPosition["abbaabbaa", "bb"].
  • With the default option setting Overlaps -> True, StringPosition includes substrings that overlap. With the setting Overlaps -> False such substrings are excluded.
  • Setting the option IgnoreCase -> True makes StringPosition treat lower- and upper-case letters as equivalent.
  • Example: StringPosition["abAB", "a", IgnoreCase -> True].
  • StringPosition returns sequence specifications in the form used by StringTake, StringDrop and StringReplacePart.
  • See the Mathematica book: Section 2.7.2.
  • See also: Position, Characters, FindList, ReplaceList.

    Further Examples

    The letter "t" occurs in the and positions of this string.

    In[1]:=

    Out[1]=