Wolfram Language & System 10.4 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

StringPartition

StringPartition["string",n]
partitions string into nonoverlapping substrings of length n.

StringPartition["string",n,d]
generates substrings with offset d.

DetailsDetails

  • 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.

ExamplesExamplesopen allclose all

Basic Examples  (3)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]=
Introduced in 2015
(10.1)
| Updated in 2016
(10.4)