dojo.trim¶
Status: | Final |
---|---|
Version: | 1.4 |
Available: | since V1.2 |
Author: | Eugene Lazutkin |
Contents
This function implements a frequently required functionality: it removes white-spaces from both ends of a string. This functionality is part of ECMAScript 5 standard and implemented by some browsers. In this case dojo.trim delegates to the native implementation. More information can be found here: String.trim() at MDC.
Dojo’s implementation was informed by Steven Levithan’s blog post. We chose to implement the compact yet performant version. If your application requires even more speed, check out dojo.string.trim, which implements the fastest version.
Basic Usage¶
dojo.trim accepts the only argument: a string to be trimmed.
Examples:
1 2 3 4 5 6 7 8 9 | function show(str){
return "|" + dojo.trim(str) + "|";
}
var output1 = show(" one");
var output2 = show("two ");
var output3 = show(" three ");
var output4 = show("\tfour\r\n");
var output5 = show("\f\n\r\t\vF I V E\f\n\r\t\v");
|
You can see the result here:
Examples of dojo.trim().
Minimalistic HTML for our example.