PDA

View Full Version : JavaScript String Object



JizzaBeez
03-03-2011, 10:05 AM
The String object is used to manipulate a stored piece of text.

Try it Yourself - Examples

Return the length of a string (http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_length_string)
How to return the length of a string.

Style strings (http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_str_style)
How to style strings.

The toLowerCase() and toUpperCase() methods (http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_lower_upper)
How to convert a string to lowercase or uppercase letters.

The match() method (http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_match)
How to search for a specified value within a string.

Replace characters in a string - replace() (http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_replace)
How to replace a specified value with another value in a string.

The indexOf() method (http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_indexof)
How to return the position of the first found occurrence of a specified value in a string.


Complete String Object Reference

For a complete reference of all the properties and methods that can be used with the String object, go to our complete String object reference (http://www.w3schools.com/jsref/jsref_obj_string.asp).

The reference contains a brief description and examples of use for each property and method!


String object

The String object is used to manipulate a stored piece of text.

Examples of use:
The following example uses the length property of the String object to find the length of a string:

var txt="Hello world!";
document.write(txt.length); The code above will result in the following output:

12 The following example uses the toUpperCase() method of the String object to convert a string to uppercase letters:

var txt="Hello world!";
document.write(txt.toUpperCase()); The code above will result in the following output:

HELLO WORLD!