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.

Details

  • StringTake["string",UpTo[n]] gives n characters, or as many as are available.
  • StringTake["string",{m,n,s}] gives characters m through n in steps of s.
  • StringTake uses the standard Wolfram Language sequence specification.

Examples

open allclose all

Basic Examples  (3)

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

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]=

Scope  (5)

Properties & Relations  (3)

Possible Issues  (2)

See Also

StringPart  Take  StringDrop  StringPosition  StringStartsQ  StringPartition  FileNameTake

Tutorials

Introduced in 1991
(2.0)
| Updated in 2015
(10.3)