StringTrim["string"]
trims whitespace from the beginning and end of "string".
StringTrim["string",patt]
trims substrings matching patt from the beginning and end.
StringTrim
StringTrim["string"]
trims whitespace from the beginning and end of "string".
StringTrim["string",patt]
trims substrings matching patt from the beginning and end.
Details and Options
- Whitespace is taken to include any number of spaces, tabs, and newlines.
- StringTrim[{s1,s2,…},…] gives the list of results for each of the si.
- StringTrim takes the following option:
-
IgnoreCase False whether to turn off case-sensitive matching
Examples
open all close allBasic Examples (3)
Remove whitespace from ends of strings:
StringTrim[" aaa bbb ccc "]//FullFormRemove multiple character types:
StringTrim["++++aaa bbb ccc----", ("+" | "-")...]//FullFormRemove initial space characters using a regular expression pattern:
StringTrim[" aaa bbb ccc ", RegularExpression["^ *"]]//FullFormScope (1)
StringTrim automatically threads over lists of strings:
StringTrim[{" aaa bbb ccc ", " aa bb cc dd "}]//FullFormSee Also
Related Guides
History
Text
Wolfram Research (2008), StringTrim, Wolfram Language function, https://reference.wolfram.com/language/ref/StringTrim.html.
CMS
Wolfram Language. 2008. "StringTrim." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/StringTrim.html.
APA
Wolfram Language. (2008). StringTrim. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringTrim.html
BibTeX
@misc{reference.wolfram_2026_stringtrim, author="Wolfram Research", title="{StringTrim}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/StringTrim.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_stringtrim, organization={Wolfram Research}, title={StringTrim}, year={2008}, url={https://reference.wolfram.com/language/ref/StringTrim.html}, note=[Accessed: 13-June-2026]}