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:

Partition a string with an offset of 1:

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

Possible Issues  (1)

Some elements of the original string may not appear in any substring:

Neat Examples  (1)

Partition a sequence of base pairs into codons:

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