Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > String Manipulation > String Operations >

StringTake

StringTake["string", n]
gives a string containing the first n characters in "string".
StringTake["string", -n]
gives the last n characters in "string".
StringTake["string", {n}]
gives the n^(th) character in "string".
StringTake["string", {m, n}]
gives characters m through n in "string".
StringTake["string", {spec1, spec2, ...}]
gives a list of the substrings specified by the speci.
StringTake[{s1, s2, ...}, spec]
gives the list of results for each of the si.
  • StringTake["string", {m, n, s}] gives characters m through n in steps of s.
  • StringTake uses the standard Mathematica sequence specification.
Take the first 6 characters in a string:
Use InputForm to show quotes:
Take from the end of the string:
Take characters 5 through 10:
Take the first 6 characters in a string:
In[1]:=
Click for copyable input
Out[1]=
Use InputForm to show quotes:
In[2]:=
Click for copyable input
Out[2]//InputForm=
 
Take from the end of the string:
In[1]:=
Click for copyable input
Out[1]=
 
Take characters 5 through 10:
In[1]:=
Click for copyable input
Out[1]=
Find character 6 in a string:
Take every other character:
Take the last 2 characters from several strings:
StringTake works with special characters:
Newline (\n) counts as a single character:
StringTake can effectively do "part" extraction in strings:
StringTake works like applying Take to the list of characters:
Taking between positions 1 and 0 gives a zero-length string:
StringTake operates on the raw characters in a string:
New in 2 | Last modified in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team