StringSplitStringSplit is useful for splitting a string into many strings at delimiters matching a pattern. By default, the splits happen at runs of whitespace. In[81]:=  |
Out[81]=
|
For instance, to split a normal sentence into words, we need to also include punctuation in the delimiter. In[82]:=  |
Out[82]=
|
By default, empty strings at the beginning and the end of the result are removed. In[83]:=  |
Out[83]=
|
These can be included by specifying All as a third argument. In[84]:=  |
Out[84]=
|
The third argument can also be a number giving the maximum number of strings to split into. In[85]:=  |
Out[85]=
|
This splits a string into individual lines. In[86]:=  |
Out[86]=
|
You can also split at patterns that match positions, such as StartOfLine. This keeps the newline characters in the result. In[87]:=  |
Out[87]=
|
You can keep the delimiters, or parts of the delimiters, in the output by using a rule as the second argument. In[88]:=  |
Out[88]=
|
In[89]:=  |
Out[89]=
|
In[90]:=  |
Out[90]=
|
In[91]:=  |
Out[91]=
|
You can give a list of patterns and rules as well; the delimiters matching the patterns will be left out of the result. In[92]:=  |
Out[92]//InputForm=
|
|