HTML and CSS Reference
In-Depth Information
Table 9.10 Methods for String Manipulation (continued)
What It Does
Searches for the regular expression and returns the index
of where it was found.
slice(startpos, endpos)
Returns string containing the part of the string from
startpos to endpos.
Splits a string into an array of words based on delimiter.
substr(startpos, endpos)
Returns a subset of string starting at startpos up to, but
not including, endpos.
Returns a copy of the string converted to lowercase.
Returns a copy of the string converted to uppercase.
Converts all characters in a string to lowercase letters.
Returns the same string as the source string.
Converts all characters in a string to uppercase letters.
Returns the string value of the object.
Methods That Find a Position in a String. A substring is a piece of an already
existing string; thus eat is a substring of both create and upbeat , and Java is a substring
of JavaScript . When a user enters information, you want to see if a certain pattern of
characters exist, such as the @ in an e-mail address or a zip code in an address. JavaScript
provides a number of methods to assist you in finding substrings.
The indexOf() and the lastIndexOf() methods are used to find the first instance or the
last instance of a substring within a larger string. They are both case sensitive. The first
character in a string is at index value 0, just like array indexes. If either of the methods
finds the substring, it returns the position of the first letter in the substring. If either
method can't find the pattern in the string, then a -1 is returned.
<body bgcolor="lightgreen">
<font face="arial"
Searching for an @ sign
<script type="text/javascript">
var email_addr=prompt("What is your email address? ","");
Search WWH ::

Custom Search