What are the various properties and method assoiated with String object? Explain with example?
Some of the commonly used properties and
method associated with String object are:
Length - Returns the length of string in
characters
toLowerCase() – Converts the string as a
string of lowercase characters.
toUpperCase() – Converts the string as a
string of Uppercase characters.
toString() – Returns the string value of
object.
Substring(Start,end) – Returns a part of
string that is extracted from the start position and ends just before end
position specified using end parameter.
Replace(expression,newstring) – It replace
any matches with newstring.
Example :-
<html>
<head><title>String
object</title></head>
<body>
<script
language="Javascript">
<!--
str="Welcome";
document.write("str.length =
"+str.length + "<br>");
document.write("str.toLowerCase =
"+ str.toLowerCase() + "<br>");
document.write("str.toUpperCase =
"+ str.toUpperCase() + "<br>");
document.write("str.substring =
"+str.substring(3) + "<br>");
-->
</script>
</body>
</html>
Comments
Post a Comment