Jump to content

Trimming (computer programming)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pengo (talk | contribs) at 03:52, 24 March 2006 (creation). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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)