15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

482<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Listing 34-6 (continued)<br />

string.substr()<br />

(&nbsp;<br />

0<br />

1<br />

2<br />

3<br />

5<br />

,<br />

<br />

(None)<br />

5<br />

10<br />

20<br />

&nbsp;) <br />

<br />

<br />

<br />

<br />

<br />

<br />

string.substring(indexA, indexB)<br />

stringObject.substring()<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

Listing 34-7 lets you experiment with a variety of values to see how the<br />

string.substring() method works. If you are using Navigator 4, try changing the<br />

LANGUAGE attribute of the script to <strong>JavaScript</strong>1.2 and see the different behavior<br />

when you set the parameters to 5 and 3. The parameters switch themselves, essentially<br />

letting the second index value become the beginning of the extracted substring.<br />

Listing 34-7: Reading a Portion of a String<br />

<br />

<br />

String Slicing and Dicing, Part III<br />

<br />

var mainString = “Electroencephalograph”<br />

function showResults() {

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!