Operations on Strings
Mathematica provides a variety of functions for manipulating strings. Most of these functions are based on viewing strings as a sequence of characters, and many of the functions are analogous to ones for manipulating lists.
s_{1}<>s_{2}<>... or StringJoin[{s_{1},s_{2},...}] 
 join several strings together 
StringLength[s]  give the number of characters in a string 
StringReverse[s]  reverse the characters in a string 
Operations on complete strings.
You can join together any number of strings using <>.
Out[1]=  

StringTake[s,n]  make a string by taking the first n characters from s 
StringTake[s,{n}]  take the n^{th} character from s 
StringTake[s,{n_{1},n_{2}}]  take characters n_{1} through n_{2} 
StringDrop[s,n]  make a string by dropping the first n characters in s 
StringDrop[s,{n_{1},n_{2}}]  drop characters n_{1} through n_{2} 
Taking and dropping substrings.
StringTake and StringDrop are the analogs for strings of Take and Drop for lists. Like Take and Drop, they use standard Mathematica sequence specifications, so that, for example, negative numbers count character positions from the end of a string. Note that the first character of a string is taken to have position 1.
This takes the first five characters from alpha.
Out[5]=  

Here is the fifth character in alpha.
Out[6]=  

This drops the characters 10 through 2, counting from the end of the string.
Out[7]=  

StringInsert[s,snew,n]  insert the string snew at position n in s 
StringInsert[s,snew,{n_{1},n_{2},...}] 
 insert several copies of snew into s 
Inserting into a string.
StringInsert[s, snew, n] is set up to produce a string whose n^{th} character is the first character of snew.
This produces a new string whose fourth character is the first character of the string "XX".
Out[8]=  

Negative positions are counted from the end of the string.
Out[9]=  

Each copy of "XXX" is inserted at the specified position in the original string.
Out[10]=  

StringReplacePart[s,snew,{m,n}] 
 replace the characters at positions m through n in s by the string snew 
StringReplacePart[s,snew,{{m_{1},n_{1}},{m_{2},n_{2}},...}] 
 replace several substrings in s by snew 
StringReplacePart[s,{snew_{1},snew_{2},...},{{m_{1},n_{1}},{m_{2},n_{2}},...}] 
 replace substrings in s by the corresponding snew_{i} 
Replacing parts of a string.
This replaces characters 2 through 6 by the string "XXX".
Out[12]=  

This replaces two runs of characters by the string "XXX".
Out[13]=  

Now the two runs of characters are replaced by different strings.
Out[14]=  

StringPosition[s,sub]  give a list of the starting and ending positions at which sub appears as a substring of s 
StringPosition[s,sub,k]  include only the first k occurrences of sub in s 
StringPosition[s,{sub_{1},sub_{2},...}] 
 include occurrences of any of the sub_{i} 
Finding positions of substrings.
You can use StringPosition to find where a particular substring appears within a given string. StringPosition returns a list, each of whose elements corresponds to an occurrence of the substring. The elements consist of lists giving the starting and ending character positions for the substring. These lists are in the form used as sequence specifications in StringTake, StringDrop and StringReplacePart.
This gives a list of the positions of the substring "abc".
Out[15]=  

This gives only the first occurrence of "abc".
Out[16]=  

This shows where both "abc" and "cd" appear. By default, overlaps are included.
Out[17]=  

This does not include overlaps.
Out[18]=  

StringCount[s,sub]  count the occurrences of sub in s 
StringCount[s,{sub_{1},sub_{2},...}]  count occurrences of any of the sub_{i} 
StringFreeQ[s,sub]  test whether s is free of sub 
StringFreeQ[s,{sub_{1},sub_{2},...}]  test whether s is free of all the sub_{i} 
Testing for substrings.
This counts occurrences of either substring, by default not including overlaps.
Out[19]=  

StringReplace[s,sb>sbnew]  replace sb by sbnew wherever it appears in s 
StringReplace[s,{sb_{1}>sbnew_{1},sb_{2}>sbnew_{2},...}] 
 replace sb_{i} by the corresponding sbnew_{i} 
StringReplace[s,rules,n]  do at most n replacements 
StringReplaceList[s,rules]  give a list of the strings obtained by making each possible single replacement 
StringReplaceList[s,rules,n]  give at most n results 
Replacing substrings according to rules.
This replaces all occurrences of the character a by the string XX.
Out[20]=  

This replaces abc by Y, and d by XXX.
Out[21]=  

The first occurrence of cde is not replaced because it overlaps with abc.
Out[22]=  

StringReplace scans a string from left to right, doing all the replacements it can, and then returning the resulting string. Sometimes, however, it is useful to see what all possible single replacements would give. You can get a list of all these results using StringReplaceList.
This gives a list of the results of replacing each of the a's.
Out[23]=  

This shows the results of all possible single replacements.
Out[24]=  

Splitting strings.
This splits the string at every run of spaces.
Out[25]=  

This splits at each colon or space.
Out[27]=  

StringSplit[s,del>rhs]  insert rhs at the position of each delimiter 
StringSplit[s,{del_{1}>rhs_{1},del_{2}>rhs_{2},...}] 
 insert rhs_{i} at the position of the corresponding del_{i} 
Splitting strings with replacements for delimiters.
This inserts {x, y} at each :: delimiter.
Out[28]=  

Sort[{s_{1},s_{2},s_{3},...}]  sort a list of strings 
Sorting strings.






