Trimming (computer programming): Difference between revisions

Content deleted Content added
Monkbot (talk | contribs)
m Task 18 (cosmetic): eval 2 templates: del empty params (1×); hyphenate params (2×);
m Bot: http → https
 
(2 intermediate revisions by 2 users not shown)
Line 15:
===Left or right trimming===
 
The 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.<ref>{{cite web|url=httphttps://www.freepascal.org/docs-html/rtl/sysutils/trim.html |title=Trim |publisher=Freepascal.org |date=2013-02-02 |access-date=2013-08-24}}</ref>
 
===Whitespace character list parameterization===
Line 36:
The 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 <code>isWhitespace()</code> method,<ref>{{cite web|url=httphttps://java.sun.com/j2se/1.5.0/docs/api/java/lang/Character.html#isWhitespace(char) |title=Character (Java 2 Platform SE 5.0) |publisher=Java.sun.com |access-date=2013-08-24}}</ref> which recognizes all Unicode space characters.
 
Delphi's Trim function considers characters U+0000 (NULL) through U+0020 (SPACE) to be whitespace.
Line 53:
 
==External links==
*[httphttps://www.tcl.tk/man/tcl8.4/TclCmd/string.htm#M46 Tcl: string trim]
*[httphttps://blog.stevenlevithan.com/archives/faster-trim-javascript Faster JavaScript Trim] - compares various JavaScript trim implementations
*[http://webwidetutor.com/php/PHP-Change-String-value-behaviour-or-look-?id=8 php string cut and trimming]- php string cut and trimming