StringTakeDrop["string",n]
gives a pair of strings containing the first n characters in "string" and the remaining characters.
StringTakeDrop["string",seq]
gives the pair {StringTake["string",seq],StringDrop["string",seq]}.
StringTakeDrop
StringTakeDrop["string",n]
gives a pair of strings containing the first n characters in "string" and the remaining characters.
StringTakeDrop["string",seq]
gives the pair {StringTake["string",seq],StringDrop["string",seq]}.
Details
- StringTakeDrop uses the standard sequence specification:
-
All all characters None no characters n characters 1 through n UpTo[n] characters 1 up to at most n, as available -n last n characters {n} character n only {m,n} characters m through n inclusive {m,n,s} characters m through n in steps of s - StringTakeDrop[{string1,string2,…},seq] returns {StringTakeDrop[string1,seq],StringTakeDrop[string2,seq],…}.
- StringTakeDrop[BioSequence["type","seq"],spec] will apply the operation to the string "seq", yielding a BioSequence result.
- Given a circular BioSequence and a starting position greater than the ending position, i.e. m>n, then StringTakeDrop[bioseq,{m,n}] takes the wrapped-around sequence starting at m and ending at n.
Examples
open all close allBasic Examples (3)
Separate the first 6 characters in a string from the rest:
StringTakeDrop["abcdefghijklmn", 6]Take some characters from the middle of a string and catenate the rest:
StringTakeDrop["abcdefghijklmn", {5, 8}]Separate a string into substrings of given lengths:
FoldPairList[StringTakeDrop, "abcdefghijklmn", {2, 3, 4, 5}]Scope (5)
StringTakeDrop uses the standard sequence specification:
StringTakeDrop["abcdefg", 3]StringTakeDrop["abcdefg", -3]StringTakeDrop["abcdefg", {3}]StringTakeDrop["abcdefg", {2, 4}]StringTakeDrop["abcdefg", {2, 6, 2}]StringTakeDrop["abcdefg", All]StringTakeDrop["abcdefg", None]Take up to 8 characters in the first string, or as many as are available:
StringTakeDrop["abcdefg", UpTo[8]]StringTakeDrop is listable in its first argument:
StringTakeDrop[{"first", "second", "third"}, 2]Take and drop a codon from a biomolecular sequence:
StringTakeDrop[BioSequence["DNA", "GTCTCGCGTAGC"], {4, 6}]Undertake a wraparound take and drop on a circular sequence:
StringTakeDrop[BioSequence["CircularDNA", "CGGTTA"], {5, 2}]Applications (1)
Break a list of structured strings by given lengths:
data = {"2020-11-20HI1.231", "2020-11-21ME0.765", "2020-11-22LO0.005"};FoldPairList[StringTakeDrop, #, {10, 2, 5}]& /@ dataThis can also be achieved with StringTake using a list of sequence specs:
StringTake[data, {1 ;; 10, 11 ;; 12, 13 ;; 17}]Properties & Relations (2)
StringTakeDrop is equivalent to a combination of StringTake and StringDrop:
string = StringJoin[Alphabet[]]StringTakeDrop[string, 8]{StringTake[string, 8], StringDrop[string, 8]}StringTakeDrop does for strings what TakeDrop does for lists:
string = "WolframLanguage";StringTakeDrop[string, 7]characters = Characters[string]TakeDrop[characters, 7]Tech Notes
Related Guides
Text
Wolfram Research (2021), StringTakeDrop, Wolfram Language function, https://reference.wolfram.com/language/ref/StringTakeDrop.html (updated 2022).
CMS
Wolfram Language. 2021. "StringTakeDrop." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/StringTakeDrop.html.
APA
Wolfram Language. (2021). StringTakeDrop. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringTakeDrop.html
BibTeX
@misc{reference.wolfram_2026_stringtakedrop, author="Wolfram Research", title="{StringTakeDrop}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/StringTakeDrop.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_stringtakedrop, organization={Wolfram Research}, title={StringTakeDrop}, year={2022}, url={https://reference.wolfram.com/language/ref/StringTakeDrop.html}, note=[Accessed: 13-June-2026]}