StringTake["string",n]
gives a string containing the first n characters in "string".
StringTake["string",-n]
gives the last n characters in "string".
StringTake["string",{n}]
gives the n
character in "string".
StringTake["string",{m,n}]
gives characters m through n in "string".
StringTake["string",{spec1,spec2,…}]
gives a list of the substrings specified by the speci.
StringTake[{s1,s2,…},spec]
gives the list of results for each of the si.
StringTake
StringTake["string",n]
gives a string containing the first n characters in "string".
StringTake["string",-n]
gives the last n characters in "string".
StringTake["string",{n}]
gives the n
character in "string".
StringTake["string",{m,n}]
gives characters m through n in "string".
StringTake["string",{spec1,spec2,…}]
gives a list of the substrings specified by the speci.
StringTake[{s1,s2,…},spec]
gives the list of results for each of the si.
Details
- StringTake["string",UpTo[n]] gives n characters, or as many as are available.
- StringTake["string",{m,n,s}] gives characters m through n in steps of s.
- StringTake uses the standard Wolfram Language sequence specification.
- StringTake[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 StringTake[bioseq,{m,n}] takes the wrapped-around sequence starting at m and ending at n.
Examples
open all close allBasic Examples (3)
Take the first 6 characters in a string:
StringTake["abcdefghijklm", 6]Use InputForm to show quotes:
InputForm[%]Take from the end of the string:
StringTake["abcdefghijklm", -4]StringTake["abcdefghijklm", {5, 10}]Scope (7)
StringTake["abcdefghijklm", {6}]InputForm[%]StringTake["abcdefghijklm", {1, -1, 2}]Take the last 2 characters from several strings:
StringTake[{"abcdef", "stuv", "xyzw"}, -2]StringTake works with special characters:
StringTake["◆αβγ⟷𝒜ℬ𝒞↵", -4]Take the first 4 characters if possible, else as many as are available:
StringTake["abc", UpTo[4]]Take a codon from a biomolecular sequence:
StringTake[BioSequence["DNA", "GTCTCGCGTAGC"], {4, 6}]Perform a wraparound take on a circular sequence:
StringTake[BioSequence["CircularDNA", "CGGTTA"], {5, 2}]Properties & Relations (3)
Newline (\n) counts as a single character:
StringTake["abc
def", 5]StringTake can effectively do "part" extraction in strings:
Characters["abcdefghijklm"][[6]]StringTake["abcdefghijklm", {6}]StringTake works like applying Take to the list of characters:
Take[Characters["abcdefghijklm"], {5, -4}]StringTake["abcdefghijklm", {5, -4}]Possible Issues (2)
Taking between positions 1 and 0 gives a zero-length string:
StringTake["abcdef", {1, 0}]FullForm[%]StringTake operates on the raw characters in a string:
StringTake["red", -20]FullForm["red"]See Also
StringPart Take StringDrop StringTakeDrop StringPosition StringStartsQ StringPartition FileNameTake
Function Repository: TextTake
Tech Notes
Related Guides
History
Introduced in 1991 (2.0) | Updated in 1999 (4.0) ▪ 2000 (4.1) ▪ 2002 (4.2) ▪ 2004 (5.1) ▪ 2014 (10.0) ▪ 2015 (10.3) ▪ 2020 (12.2)
Text
Wolfram Research (1991), StringTake, Wolfram Language function, https://reference.wolfram.com/language/ref/StringTake.html (updated 2020).
CMS
Wolfram Language. 1991. "StringTake." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/StringTake.html.
APA
Wolfram Language. (1991). StringTake. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringTake.html
BibTeX
@misc{reference.wolfram_2026_stringtake, author="Wolfram Research", title="{StringTake}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/StringTake.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_stringtake, organization={Wolfram Research}, title={StringTake}, year={2020}, url={https://reference.wolfram.com/language/ref/StringTake.html}, note=[Accessed: 13-June-2026]}