StringPart

StringPart["string",n]

gives the n^(th) character in "string".

StringPart["string",{n1,n2,}]

gives a list of the ni^(th) characters in "string".

StringPart["string",m;;n;;s]

gives a list of the characters in "string" from the m^(th) through the n^(th) in steps of s.

StringPart[{s1,s2,},spec]

gives the list of results for each of the si.

Details

  • StringPart["string",-n] counts from the end to give the n^(th)-to-last character in "string".
  • StringPart gives each character as a string.
  • In StringPart["string",m;;n;;s], m, n, and/or s can be negative.

Examples

open allclose all

Basic Examples  (3)

Extract the sixth character 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=

Extract several characters from a string:

In[1]:=
Click for copyable input
Out[1]=

Extract a character from the end of a string:

In[1]:=
Click for copyable input
Out[1]=

Scope  (5)

Properties & Relations  (7)

Possible Issues  (1)

See Also

StringTake  Part  Characters  StringPosition

Introduced in 2016
(11.0)