partitions string into nonoverlapping substrings of length n.


generates substrings with offset d.


  • 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.
  • StringPartition[BioSequence["type","seq"],n,] will apply the operation to the string "seq", yielding a list of BioSequence results.


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:

Scope  (1)

Partition a DNA sequence into codons:

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:

Wolfram Research (2015), StringPartition, Wolfram Language function, (updated 2020).


Wolfram Research (2015), StringPartition, Wolfram Language function, (updated 2020).


Wolfram Language. 2015. "StringPartition." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020.


Wolfram Language. (2015). StringPartition. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2022_stringpartition, author="Wolfram Research", title="{StringPartition}", year="2020", howpublished="\url{}", note=[Accessed: 28-June-2022 ]}


@online{reference.wolfram_2022_stringpartition, organization={Wolfram Research}, title={StringPartition}, year={2020}, url={}, note=[Accessed: 28-June-2022 ]}