15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

String and<br />

Number Objects<br />

(Chapters 34<br />

and 35)<br />

Knowing how to manipulate strings of text characters is a<br />

vital programming skill. You may not have to do it all<br />

the time, but you should be fully aware of the possibilities for<br />

this manipulation that are built into whatever programming<br />

language you use. In <strong>JavaScript</strong> (as in any object-based or<br />

object-oriented language), strings are objects that have<br />

numerous properties and methods to assist in assembling,<br />

tearing apart, extracting, and copying chunks of strings.<br />

Any characters that users enter into text boxes become<br />

parts of string objects. In IE4+ and NN6, text inside HTML<br />

element tags can be treated as strings. In IE4+, you can even<br />

work with the HTML tags as strings. Therefore, of all the core<br />

language objects to implant in your scripting consciousness,<br />

the string object is it (arrays, whose examples come in the<br />

next chapter of this book, rank Number Two on the list).<br />

Numbers are much less frequently thought of as objects<br />

because they tend to be used as-is for calculations. <strong>JavaScript</strong><br />

1.5 in recent browsers, however, endows the number object<br />

with practical methods, especially one that (finally) offers<br />

built-in control over the number of digits displayed to the<br />

right of the decimal point for floating-point numbers.<br />

When examples in this chapter encourage you to enter a<br />

sequence of expressions in The Evaluator, be sure to follow<br />

through with every step. But also make sure you understand<br />

the results of each expression in order to visualize the particular<br />

method operates.<br />

16<br />

C H A P T E R<br />

✦ ✦ ✦ ✦<br />

In This Chapter<br />

Parsing text at the<br />

character level<br />

Performing searchand-replace<br />

operations with<br />

regular expressions<br />

Converting between<br />

character codes and<br />

text<br />

Setting number<br />

format and precision<br />

✦ ✦ ✦ ✦

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

Saved successfully!

Ooh no, something went wrong!