Changes

Jump to: navigation, search

JavaScript String Object

1,014 bytes added, 19:29, 27 April 2007
Manipulating Strings with the String Object
=== Manipulating Strings with the String Object ===
One of the most powerful features of the JavaScript String Object in the ability to manipulate strings. This includes breaking a string up into multiple sections, extracting fragments of a string and finding whterh whether a particular string sequence in is contained in a string.
To extract a single character from a specific index into the string:
</pre>
 
Finally, to break a string up into multiple strings based on the locations of a specified delimeter, in this case a semi-colon:
 
<pre>
 
myString = new String ("This is my string");
 
var stringArray = myString.split(";");
 
for (i=0; i<stringArray.length; i++)
{
document.write ("Fragment " + i + " = " + stringArray[i]);
}
 
// outputs Fragment 0 = hello Fragment 1 = goodbye Fragment 2 = bonjour Fragment 3 = guten tag
 
</pre>
 
== Summary ==
 
In this chapter we have looked at one of the most powerful and frequently used javaScript core objects - the String Object. As a JavaScript developer much of your time will be spent validating and manipulating string data entered by web site users. By combining the many methods of the String object it is possible to perform just about any string validation or manipulation tasks imaginable. As with any technology experimentation is the key to getting up to speed on JavaScript Strings so fire up your favorite editor and start trying out the methods described above.

Navigation menu