CNET JS Code Documentation

Native: String

A collection of the String Object prototype methods.

Author: Aaron Newton

See Also:

String Method: stripTags

Remove all html tags from a string.

Syntax

myString.stripTags();
 

Example

var html = "<b>This is a string with <i>html</i> in it.</b>"
var noHtml = html.stripTags();
//returns "This is a string with html in it."
 

Returns

  • (string) a string without any HTML tags

String Method: parseQuery

Turns a querystring into an object of key/value pairs.

Syntax

myString.parseQuery(encodeKeys, encodeValues);
 

Arguments

  1. encodeKeys - (boolean, optional) if set to false, keys are passed through encodeURIComponent; defaults to true
  2. encodeValues - (boolean, optional) if set to false, values are passed through encodeURIComponent; defaults to true

Example

"apple=red&lemon=yellow".parseQuery();
//returns { apple: "red", lemon: "yellow }
var fruits = "apple=red&lemon=yellow".parseQuery();
//returns fruits.apple > "red"
 

Returns

  • (object) the querystring as key/value pairs

String Method: tidy

Replaces common special characters with their ASCII counterparts (smart quotes, elipse characters, stuff from MS Word, etc.).

Syntax

var tidyString = stringWithBadChars.tidy();