Built-In Namespace String
| Method Attributes | Method Name and Description |
|---|---|
|
Escape RegEx special characters
|
|
|
ltrim(chars)
Trim whitespace (or nominated character(s)/Regular Expression) from the beginning of a String
|
|
|
parseQuery(seperator, convert)
Parse a query-string such as the "search" property of the document.location object
|
|
|
parseURL()
Parse a URL string into parts, simmilar to the document.location object
|
|
|
replaceMulti(findVal, replaceVal)
Replace one or more sub-strings in a String with a single new value, or with values from an Array
|
|
|
rtrim(chars)
Trim whitespace (or nominated character(s)/Regular Expression) from the end of a String
|
|
|
Common-use implementation of String#stripTags
|
|
|
stripTags(tag, removeContent)
Strip HTML or XML style tags, optionally including the tag content from a String
|
|
|
Convert a dash or space seperated String to Camel-Case
|
|
|
toDashed()
Convert a Camel-Cased String into a dash-seperated String
|
|
|
trim(chars)
Trim whitespace (or nominated character(s)/Regular Expression) from each end of a String
|
Method Detail
{String}
escapeRegex()
Escape RegEx special characters
Defined in: string.js.
Defined in: string.js.
- Returns:
- {String} the original String with all RegEx special characters escaped.
{String}
ltrim(chars)
Trim whitespace (or nominated character(s)/Regular Expression) from the beginning of a String
Defined in: string.js.
Defined in: string.js.
' foo bar '.ltrim(); //'foo bar '
'foo barf '.ltrim('f'); //'oo barf '
- Parameters:
- {String|RegEx} chars Optional, Default: whitespace
- the character(s) or Regular Expression to remove from each end of the String. Defaults to whitespace
- Returns:
- {String} the original String with the specified characters (or whitespace) removed from the beginning
- See:
- String.prototype.trim
- String.prototype.rtrim
{Object}
parseQuery(seperator, convert)
Parse a query-string such as the "search" property of the document.location object
Defined in: string.js.
Defined in: string.js.
- Parameters:
- {String} seperator Optional, Default: &
- the character seperating the name:value pairs in the string
- convert
- Returns:
- {Object} an object containing the key:value pairs in the String. Multiple entries with the same name will be returned in an Array
{Object}
parseURL()
Parse a URL string into parts, simmilar to the document.location object
Defined in: string.js.
Defined in: string.js.
- Returns:
- {Object} an object containing the parts of the URL, simmilar to the document.location object
{String}
replaceMulti(findVal, replaceVal)
Replace one or more sub-strings in a String with a single new value, or with values from an Array
Defined in: string.js.
Defined in: string.js.
- Parameters:
- {String|Array} findVal
- the sub-string(s) to find in the string
- {String|Array} replaceVal Optional, Default: ''
- the value(s) to to replace the found-substrings. A String will replace all instances of the sub-strings searched for. An Array will replace corresponding sub-strings, and must have same length as Array of sub-strings to find.
- Returns:
- {String} the new String
{String}
rtrim(chars)
Trim whitespace (or nominated character(s)/Regular Expression) from the end of a String
Defined in: string.js.
Defined in: string.js.
' foo bar '.rtrim(); //' foo bar'
'foo barf '.rtrim('f'); //'foo barf '
- Parameters:
- {String|RegEx} chars Optional, Default: whitespace
- the character(s) or Regular Expression to remove from each end of the String. Defaults to whitespace
- Returns:
- {String} the original String with the specified characters (or whitespace) removed from the end
- See:
- String.prototype.trim
- String.prototype.ltrim
{String}
stripScripts()
var str = '<div><script type="text/javascript">alert('foo');</script> and stuff!</div>';
str.stripScripts(); // '<div> and stuff</div>';
- Returns:
- {String} the original String with the SCRIPT tags (and content) removed
- Requires:
- String#stripTags
{String}
stripTags(tag, removeContent)
Strip HTML or XML style tags, optionally including the tag content from a String
Defined in: string.js.
Defined in: string.js.
var p = '<p id="moo"><strong>Moo</strong> cow</p>';
p.stripTags('p'); //'<strong>Moo</strong> cow'
p.stripTags('strong',true); //'<p id="moo"> cow</p>'
- Parameters:
- {String} tag
- the tag name to remove from the String
- {Boolean} removeContent Optional, Default: false
- flag to remove the content of the tag as well as the tag itself
- Returns:
- {String} the String with tags (and content if removeContent is true) removed
{String}
toCamelCase()
Convert a dash or space seperated String to Camel-Case
Defined in: string.js.
Defined in: string.js.
var str1 = 'some-words-here'.toCamelCase(); //'someWordsHere' var str2 = ' some words there'.toCamelCase(); //'SomeWordsThere'
- Returns:
- {String} the Camel-Cased String
{String}
toDashed()
Convert a Camel-Cased String into a dash-seperated String
Defined in: string.js.
Defined in: string.js.
var str1 = 'SomeValueHere'.toDashed(); //'-some-value-here' var str2 = 'someValueHere'.toDashed(); //'some-value-here'
- Returns:
- {String} the dash-seperated string
{String}
trim(chars)
Trim whitespace (or nominated character(s)/Regular Expression) from each end of a String
Defined in: string.js.
Defined in: string.js.
' foo bar '.trim(); //'foo bar'
'foo barf '.trim('f'); //'oo barf '
- Parameters:
- {String|RegEx} chars Optional, Default: whitespace
- the character(s) or Regular Expression to remove from each end of the String. Defaults to whitespace
- Returns:
- {String} the original String with the specified characters (or whitespace) removed from each end
- See:
- String.prototype.ltrim
- String.prototype.rtrim