6String Manipulation
WHAT YOU WILL LEARN IN THIS CHAPTER:
- Using the String object’s advanced methods to manipulate strings
- Matching substrings follow a specific pattern
- Validating useful pieces of information, such as telephone numbers, e-mail addresses, and postal codes
WROX.COM CODE DOWNLOADS FOR THIS CHAPTER
You can find the wrox.com code downloads for this chapter at http://www.wiley.com/go/BeginningJavaScript5E
on the Download Code tab. You can also view all of the examples and related files at http://beginningjs.com
.
In Chapter 5 you looked at the String
object, which is one of the native objects that JavaScript makes available to you. You saw a number of its properties and methods, including the following:
length
—The length of the string in characterscharAt()
andcharCodeAt()
—The methods for returning the character or character code at a certain position in the stringindexOf()
andlastIndexOf()
—The methods that allow you to search a string for the existence of another string and that return the character position of the string if foundsubstr()
andsubstring()
—The methods that return just a portion of a stringtoUpperCase()
andtoLowerCase()
—The methods that return a string converted to upper- or lowercase
In this chapter you look at four new methods of the String
object, namely split()
, match()
, replace()
, and search()
. The last three, in particular, give you some very powerful text-manipulation functionality. However, to make full use of this ...
Get Beginning JavaScript, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.