StringPart
StringPart["string",n]
gives the n character in "string".
StringPart["string",{n1,n2,…}]
gives a list of the ni characters in "string".
StringPart["string",m;;n;;s]
gives a list of the characters in "string" from the m through the n in steps of s.
StringPart[{s1,s2,…},spec]
gives the list of results for each of the si.
Details
- StringPart["string",-n] counts from the end to give the n-to-last character in "string".
- StringPart gives each character as a string.
- In StringPart["string",m;;n;;s], m, n, and/or s can be negative.
- StringPart[BioSequence["type","seq"],spec] will apply the operation to the string "seq" yielding BioSequence results.
Examples
open allclose allBasic Examples (3)
Extract the sixth character in a string:
Use InputForm to show quotes:
Scope (6)
Obtain the first six characters of a string:
Obtain a list of every other character:
Obtain a list of every other character, starting from the end of the string:
Get the first character of each of several strings:
Find the first and last characters:
StringPart works with special characters:
Properties & Relations (7)
StringPart[str,{}] returns the empty list:
StringPart works like applying Part to the list of characters:
The characters in the list returned by StringPart can be turned into a string using StringJoin:
StringPart[str,n] is effectively equivalent to StringTake[str,{n}]:
StringPart[str,n;;m;;s] returns a list of characters:
StringTake[str,{n,m,s}] returns the same characters as a single string:
StringPart[str,All] is effectively equivalent to Characters[str]:
StringPart operates on the raw characters in a string:
Possible Issues (1)
StringPosition gives results in a form suitable for StringTake, not StringPart:
Text
Wolfram Research (2016), StringPart, Wolfram Language function, https://reference.wolfram.com/language/ref/StringPart.html (updated 2020).
CMS
Wolfram Language. 2016. "StringPart." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/StringPart.html.
APA
Wolfram Language. (2016). StringPart. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringPart.html