Trimming (computer programming)
Appearance
In programming, trim or strip is a string manipulation function which removes leading and trailing whitespace from a string.
For example, in Python:
' this is a test '.strip()
will return the string:
'this is a test'
Other varients of the trim function which are available in some languages include:
- trimming only the beginning or the end of the string
- allowing the selection of which whitespace (or other) characters to trim
- returning a special result if no characters are left to be returned after the trim operation.
Examples
Java:
string.trim()
Python:
string.strip()
C#:
String.Trim()
Apache Java libraries:
org.apache.commons.lang.StringUtils.strip(string)