Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Previous section-----Next section

2.8.3 Characters in Strings

Characters["string"] convert a string to a list of characters
StringJoin[{" ", " ", ... }] convert a list of characters to a string

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

DigitQ[string] test whether all characters in a string are digits
LetterQ[string] test whether all characters in a string are letters
UpperCaseQ[string] test whether all characters in a string are upper-case letters
LowerCaseQ[string] test whether all characters in a string are lower-case letters

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

ToUpperCase[string] generate a string in which all letters are upper case
ToLowerCase[string] generate a string in which all letters are lower case

Converting between upper and lower case.
This converts all letters to upper case.

In[6]:=  ToUpperCase["Mixed Form"]

Out[6]=

CharacterRange[" ", " "] generate a list of all characters from  and

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

Out[10]=


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2008 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: