Trimming (computer programming)
In computer programming, trimming (trim) or stripping (strip) is a string manipulation in which leading and trailing whitespace is removed from a string. For example, the string (enclosed by apostrophes) ' this is a test '
would be changed, after trimming, to 'this is a test'
VariantsLeft or right trimmingThe most popular variants of the trim function strip only the beginning or end of the string. Typically named ltrim and rtrim respectively, or in the case of Python: lstrip and rstrip. C# uses TrimStart and TrimEnd, and Common Lisp string-left-trim and string-right-trim. Pascal and Java do not have these variants built-in, although Object Pascal (Delphi) has TrimLeft and TrimRight functions.[1] Whitespace character list parameterizationMany trim functions have an optional parameter to specify a list of characters to trim, instead of the default whitespace characters. For example, PHP and Python allow this optional parameter, while Pascal and Java do not. With Common Lisp's Special empty string return valueAn uncommon variant of trim returns a special result if no characters remain after the trim operation. For example, Apache Jakarta's StringUtils has a function called Space normalizationSpace normalization is a related string manipulation where in addition to removing surrounding whitespace, any sequence of whitespace characters within the string is replaced with a single space. Space normalization is performed by the function named In-place trimmingWhile most algorithms return a new (trimmed) string, some alter the original string in-place. Notably, the Boost library allows either in-place trimming or a trimmed copy to be returned. Definition of whitespaceThe characters which are considered whitespace varies between programming languages and implementations. For example, C traditionally only counts space, tab, line feed, and carriage return characters, while languages which support Unicode typically include all Unicode space characters. Some implementations also include ASCII control codes (non-printing characters) along with whitespace characters. Java's trim method considers ASCII spaces and control codes as whitespace, contrasting with the Java Delphi's Trim function considers characters U+0000 (NULL) through U+0020 (SPACE) to be whitespace. Non-space blanksThe Braille Patterns Unicode block contains U+2800 ⠀ BRAILLE PATTERN BLANK, a Braille pattern with no dots raised. The Unicode standard explicitly states that it does not act as a space. The Non-breaking space U+00A0 NO-BREAK SPACE ( ,  ) can also be treated as non-space for trimming purposes. UsageReferences
External links
|
Portal di Ensiklopedia Dunia