This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / The Mathematica Book / Principles of Mathematica / Strings and Characters  /

2.7.4 Characters in Strings

Converting between strings and lists of characters.

  • This gives a list of the characters in the string.
  • In[1]:= Characters["A string."]


  • You can apply standard list manipulation operations to this list.
  • In[2]:= RotateLeft[%, 3]


  • StringJoin converts the list of characters back to a single string.
  • In[3]:= StringJoin[%]


    Testing characters in a string.

  • All characters in the string given are letters.
  • In[4]:= LetterQ["Mixed"]


  • Not all the letters are upper case, so the result is False.
  • In[5]:= UpperCaseQ["Mixed"]


    Converting between upper and lower case.

  • This converts all letters to upper case.
  • In[6]:= ToUpperCase["Mixed Form"]


    Generating ranges of characters.

  • This generates a list of lower-case letters in alphabetical order.
  • In[7]:= CharacterRange["a", "h"]


  • Here is a list of upper-case letters.
  • In[8]:= CharacterRange["T", "Z"]


  • Here are some digits.
  • In[9]:= CharacterRange["0", "7"]


    CharacterRange will usually give meaningful results for any range of characters that have a natural ordering. The way CharacterRange works is by using the character codes that Mathematica internally assigns to every character.

  • This shows the ordering defined by the internal character codes used by Mathematica.
  • In[10]:= CharacterRange["T", "f"]