StringPartition

StringPartition["string",n]

partitions string into nonoverlapping substrings of length n.

StringPartition["string",n,d]

generates substrings with offset d.

Details

  • All the substrings generated by StringPartition[string,n,d] are of length n. Some elements at the end of string may therefore not appear in any substring.
  • StringPartition[string,UpTo[n]] partitions into substrings of length up to n, allowing the final substring to be shorter.
  • All elements of string appear in the substrings generated by StringPartition[string,n,1].
  • If d is greater than n in StringPartition[string,n,d], then elements in the middle of string are skipped.

Examples

open allclose all

Basic Examples  (3)

Partition a string into substrings of length 9:

In[1]:=
Click for copyable input
Out[1]=

Partition a string with an offset of 1:

In[1]:=
Click for copyable input
Out[1]=

Partition a string into substrings, including the shorter string at the end:

In[1]:=
Click for copyable input
Out[1]=

Possible Issues  (1)

Neat Examples  (1)

See Also

StringJoin  StringRepeat  StringSplit  StringTake  Partition  InsertLinebreaks

Introduced in 2015
(10.1)
| Updated in 2016
(10.4)