113Chapter 10Strings, Math, and DatesYou can also (Web hosting service) combine
113Chapter 10Strings, Math, and DatesYou can also combine the operators if the need arises: var msg = Four score ; msg += and seven + years ago ; I use the add-by-value operator a lot when accumulating HTML text to be written to the cur- rent document or another window. String methodsOf all the core JavaScript objects, the Stringobject has the most diverse collection of meth- ods associated with it. Many methods are designed to help scripts extract segments of astring. Another group, rarely used and now obsolete in favor of CSS, wraps a string with oneof several style-oriented tags (a scripted equivalent of tags for font size, style, and the like). To use a string method, the string being acted upon becomes part of the reference followedby the method name. All methods return a value of some kind. Most of the time, the returnedvalue is a converted version of the string object referred to in the method call but the origi- nal string is still intact. To capture the modified version, you need to assign the results of themethod to a variable: var result = string.methodName(); The following sections introduce you to several important string methods available to allbrowser brands and versions. Changing string caseTwo methods convert a string to all uppercase or lowercase letters: var result = string.toUpperCase(); var result = string.toLowerCase(); Not surprisingly, you must observe the case of each letter of the method names if you wantthem to work. These methods come in handy when your scripts need to compare strings thatmay not have the same case (for example, a string in a lookup table compared with a stringtyped by a user). Because the methods don t change the original strings attached to theexpressions, you can simply compare the evaluated results of the methods: var foundMatch = false; if (stringA.toUpperCase() == stringB.toUpperCase()) { foundMatch = true; } String searchesYou can use the string.indexOf()method to determine if one string is contained byanother. Even within JavaScript s own object data, this can be useful information. For exam- ple, the navigator.userAgentproperty reveals a lot about the browser that loads the page. A script can investigate the value of that property for the existence of, say, Win to deter- mine that the user has a Windows operating system. That short string might be buried some- where inside a long string, and all the script needs to know is whether the short string ispresent in the longer one wherever it might be.
Note: If you are looking for cheap webhost to host and run your apache application check Vision jboss web hosting services