Namespace $.js.String
Holds the methods used for manipulating strings. Some of them are
already available in JavaScript 1.6, natively.
Defined in: core-js.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Holds the methods used for manipulating strings.
|
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
$.js.String.escapeRegexp()
Escape special characters in regular expressions.
|
| <static> |
$.js.String.escapeXML()
Convert significant characters into entities.
|
| <static> |
$.js.String.stripTags()
Strip tags from a string.
|
| <static> |
$.js.String.trim()
Trim whitespace from the start and the end of the string.
|
| <static> |
$.js.String.trimLeft()
Trim whitespace from the start of the string.
|
| <static> |
$.js.String.trimRight()
Trim whitespace from the end of the string.
|
| <static> |
$.js.String.unescapeXML()
Decode significant characters from entities.
|
By default, the global String.prototype object is extended to contain all the methods in this namespace, if they do not exists already. Thus, native String methods are not overwritten.
All of these methods use their this object. As such, you need to pass the correct this object.
In the examples provided for each method we will assume that the strings
defined already have the methods. Thus code like
string.trim() can be written directly.
- Returns:
- {String} The string with the special characters escaped.
The characters being encoded are:
- ' & ' to ' & '
- ' < ' to ' < '
- ' > ' to ' > '
- ' " ' to ' " '
- " ' " to ' ' '
- Returns:
- {String} The string with the special characters encoded.
Optionally, you may provide the list of tags to be stripped from the string. Each argument is considered a tag name.
If no argument is provided, then all the tags in the string are stripped.
- Returns:
- {String} The string with tags stripped.
var str = " \n test \n "; var str2 = str.trim();// Nowstr2 = 'test'.
- Returns:
- {String} The string without any whitespace at the beginning, nor at the end.
var str = " \n test \n "; var str2 = str.trimLeft();// Nowstr2 = "test \n ".
- Returns:
- {String} The string without any whitespace at the beginning.
var str = " \n test \n "; var str2 = str.trimRight();// Nowstr2 = " \n test".
- Returns:
- {String} The string without any whitespace at the end.
- Returns:
- {String} The string with the special characters decoded.