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."]

    Out[1]=

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

    Out[2]=

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

    Out[3]=


    Testing characters in a string.

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

    Out[4]=

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

    Out[5]=


    Converting between upper and lower case.

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

    Out[6]=


    Generating ranges of characters.

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

    Out[7]=

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

    Out[8]=

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

    Out[9]=

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

    Out[10]=