Java Reference
In-Depth Information
Table 4-12.
(
continued
)
Method
Description
localeCompare(target)
Returns a number. If the string is less than
target
,
it returns a negative number; if string is greater than
target
, it returns a positive number; otherwise, it
returns zero
match(regexp)
Searches the string for the specified regular expression
regexp
and returns the results in an array
replace(regexp,
replacement)
Searches the string using the regular expression
regexp
,
replaces the matched substrings with the replacement,
and returns the result as a primitive string value
search(regexp)
Searches the string for the specified regular expression
and returns the index of the first occurrence. Returns -1
if no match is found
slice(start, end)
Returns a substring contains characters from
start
and
end
indexes in the string where
start
is inclusive
and
end
is exclusive. If
end
is not specified, it returns all
characters from
start
. If
end
is negative, the index is
counted from the end.
"Hello".slice(1, 2)
returns
"e"
and
"Hello".slice(1, -2)
returns
"el"
split(delimiter, limit)
Returns an array by splitting the string around the
specified
delimiter
. The
limit
is optional and it
specifies the maximum number of elements returned in
the array
substring(start, end)
Returns a substring of the string starting at the
start
and
up to, but not including, the
end
. If either argument is
NaN
or negative, it is replaced with zero. If they are larger
than the length of the string, they are replaced with the
length of the string. If
start
is greater than
end
, they
are swapped.
"Hello".slice(1, 2)
returns
"e"
and
"Hello".slice(1, -2)
returns
"H"
toLowerCase()
Returns the lowercase equivalent of the string by
replacing uppercase characters with the corresponding
lowercase characters
toLocaleLowerCase()
Works the same as the
toLowerCase()
, except that it
uses locale specific uppercase to lowercase character
mapping
toUpperCase()
Returns the uppercase equivalent of the string by
replacing lowercase characters with the corresponding
uppercase characters
(
continued
)
Search WWH ::
Custom Search