This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

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", patt]
gives all positions at which substrings matching the general string expression patt appear in "string".
StringPosition["string", patt, n]
includes only the first n occurrences of patt.
StringPosition["string", {patt1, patt2, ...}]
gives positions of all the patti.
StringPosition[{s1, s2, ...}, p]
gives the list of results for each of the si.
  • The string expression patt can contain any of the objects specified in the notes for StringExpression.
  • With Overlaps->All, multiple substrings that match the same string expression are all included. With Overlaps->True, only the first such matching substring at a given position is included.  »
Find the starting and ending positions at which XYZ occurs in a string:
In[1]:=
Click for copyable input
Out[1]=
 
Find where any pairs of identical characters occur:
In[1]:=
Click for copyable input
Out[1]=
New in 2 | Last modified in 5.1