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:
  • Allall characters
    Noneno characters
    ncharacters 1 through n
    UpTo[n]characters 1 up to at most n, as available
    -nlast 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],}.

Examples

open allclose all

Basic Examples  (3)

Separate the first 6 characters in a string from the rest:

Take some characters from the middle of a string and catenate the rest:

Separate a string into substrings of given lengths:

Scope  (3)

StringTakeDrop uses the standard sequence specification:

Take up to 8 characters in the first string, or as many as are available:

StringTakeDrop is listable in its first argument:

Applications  (1)

Break a list of structured strings by given lengths:

This can also be achieved with StringTake using a list of sequence specs:

Properties & Relations  (2)

StringTakeDrop is equivalent to a combination of StringTake and StringDrop:

StringTakeDrop does for strings what TakeDrop does for lists:

Wolfram Research (2021), StringTakeDrop, Wolfram Language function, https://reference.wolfram.com/language/ref/StringTakeDrop.html.

Text

Wolfram Research (2021), StringTakeDrop, Wolfram Language function, https://reference.wolfram.com/language/ref/StringTakeDrop.html.

BibTeX

@misc{reference.wolfram_2021_stringtakedrop, author="Wolfram Research", title="{StringTakeDrop}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/StringTakeDrop.html}", note=[Accessed: 26-September-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_stringtakedrop, organization={Wolfram Research}, title={StringTakeDrop}, year={2021}, url={https://reference.wolfram.com/language/ref/StringTakeDrop.html}, note=[Accessed: 26-September-2021 ]}

CMS

Wolfram Language. 2021. "StringTakeDrop." Wolfram Language & System Documentation Center. Wolfram Research. 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