WOLFRAM

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

Examples

open allclose all

Basic Examples  (3)Summary of the most common use cases

Partition a string into substrings of length 9:

Out[1]=1

Partition a string with an offset of 1:

Out[1]=1

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

Out[1]=1

Scope  (1)Survey of the scope of standard use cases

Partition a DNA sequence into codons:

Out[1]=1

Possible Issues  (1)Common pitfalls and unexpected behavior

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

Out[1]=1

Neat Examples  (1)Surprising or curious use cases

Partition a sequence of base pairs into codons:

Out[2]=2
Wolfram Research (2015), StringPartition, Wolfram Language function, https://reference.wolfram.com/language/ref/StringPartition.html (updated 2020).
Wolfram Research (2015), StringPartition, Wolfram Language function, https://reference.wolfram.com/language/ref/StringPartition.html (updated 2020).

Text

Wolfram Research (2015), StringPartition, Wolfram Language function, https://reference.wolfram.com/language/ref/StringPartition.html (updated 2020).

Wolfram Research (2015), StringPartition, Wolfram Language function, https://reference.wolfram.com/language/ref/StringPartition.html (updated 2020).

CMS

Wolfram Language. 2015. "StringPartition." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/StringPartition.html.

Wolfram Language. 2015. "StringPartition." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/StringPartition.html.

APA

Wolfram Language. (2015). StringPartition. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringPartition.html

Wolfram Language. (2015). StringPartition. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringPartition.html

BibTeX

@misc{reference.wolfram_2025_stringpartition, author="Wolfram Research", title="{StringPartition}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/StringPartition.html}", note=[Accessed: 25-March-2025 ]}

@misc{reference.wolfram_2025_stringpartition, author="Wolfram Research", title="{StringPartition}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/StringPartition.html}", note=[Accessed: 25-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_stringpartition, organization={Wolfram Research}, title={StringPartition}, year={2020}, url={https://reference.wolfram.com/language/ref/StringPartition.html}, note=[Accessed: 25-March-2025 ]}

@online{reference.wolfram_2025_stringpartition, organization={Wolfram Research}, title={StringPartition}, year={2020}, url={https://reference.wolfram.com/language/ref/StringPartition.html}, note=[Accessed: 25-March-2025 ]}