Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

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.

DetailsDetails

  • 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.

ExamplesExamplesopen allclose all

Basic Examples  (3)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

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]=
Introduced in 2016
(11.0)