Javascript String Object
String object
Examples
The string object is used to manipulate a stored piece of text
String Object
length property of the string object to find the length of a string
var txt="Hello World!";
document.write(txt.length);
output: 12
toUpperCase() method of the string object to convert a string to upper letters
var text="Hello World!";
document.write(txt.toUpperCase());
output:HELLO WORLD!
<html>
<body>
<script type="text/javascript">
var txt="Hello World!";
document.write(txt.length);
</script>
</body>
</html>
ouput:12
<html>
<body>
<script type="text/javascript">
var txt="Hello World!";
document.write("<p>Big:"+txt.big()+"</p>);
document.write("<p>Small:"+txt.small()+"</p>);
document.write("<p>Bold:"+txt.bold()+"</p>);
document.write("<p>Italic:"+txt.italics()+"</p>);
document.write("<p>Fixed:"+txt.fixed()+"</p>);
document.write("<p>Strike:"+txt.strike()+"</p>);
document.write("<p>Font Color:"+txt.fontcolor()+"</p>);
document.write("<p>Font Size:"+txt.fontsize()+"</p>);
document.write("<p>Sub Script:"+txt.sub()+"</p>);
document.write("<p>Super Script:"+txt.sup()+"</p>);
document.write("<p>Link:"+txt.link("http://www.w3schools.com")+"</p>);
document.write("<p>Blink:"+txt.blink()+"(does not work in IE, chrom, or safari)</p>);
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
var txt="Hello World!";
document.write(txt.toLowerCase()+"<br/>");
document.write(txt.toUpperCase());
</script>
</body>
</html>
how to search for a specified value within a string.
<html>
<body>
<script type="text/javascript">
var str="Hello World!";
document.write(str.match("World")+"<br/>");
document.write(str.match("world")+"<br/>");
document.write(str.match("worlld")+"<br/>");
document.write(str.match("world!")+"<br/>");
</script>
</body>
</html>
how to replace a specified value with another value in a string.
<html>
<body>
<script type="text/javascript">
var str="Visit Microsoft!";
document.write(str.replace("Microsoft","w3schools"));
</script>
</body>
</html>
how to find the position of the first occurence of a specified value in a string.
<html>
<body>
<script type="text/javascript">
document.write(str.indexof("Hello")+"<br/>");
document.write(str.indexof("World")+"<br/>");
document.write(str.indexof("world")+"<br/>");
</script>
</body>
</html>
String object
Examples
The string object is used to manipulate a stored piece of text
String Object
length property of the string object to find the length of a string
var txt="Hello World!";
document.write(txt.length);
output: 12
toUpperCase() method of the string object to convert a string to upper letters
var text="Hello World!";
document.write(txt.toUpperCase());
output:HELLO WORLD!
<html>
<body>
<script type="text/javascript">
var txt="Hello World!";
document.write(txt.length);
</script>
</body>
</html>
ouput:12
<html>
<body>
<script type="text/javascript">
var txt="Hello World!";
document.write("<p>Big:"+txt.big()+"</p>);
document.write("<p>Small:"+txt.small()+"</p>);
document.write("<p>Bold:"+txt.bold()+"</p>);
document.write("<p>Italic:"+txt.italics()+"</p>);
document.write("<p>Fixed:"+txt.fixed()+"</p>);
document.write("<p>Strike:"+txt.strike()+"</p>);
document.write("<p>Font Color:"+txt.fontcolor()+"</p>);
document.write("<p>Font Size:"+txt.fontsize()+"</p>);
document.write("<p>Sub Script:"+txt.sub()+"</p>);
document.write("<p>Super Script:"+txt.sup()+"</p>);
document.write("<p>Link:"+txt.link("http://www.w3schools.com")+"</p>);
document.write("<p>Blink:"+txt.blink()+"(does not work in IE, chrom, or safari)</p>);
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
var txt="Hello World!";
document.write(txt.toLowerCase()+"<br/>");
document.write(txt.toUpperCase());
</script>
</body>
</html>
how to search for a specified value within a string.
<html>
<body>
<script type="text/javascript">
var str="Hello World!";
document.write(str.match("World")+"<br/>");
document.write(str.match("world")+"<br/>");
document.write(str.match("worlld")+"<br/>");
document.write(str.match("world!")+"<br/>");
</script>
</body>
</html>
how to replace a specified value with another value in a string.
<html>
<body>
<script type="text/javascript">
var str="Visit Microsoft!";
document.write(str.replace("Microsoft","w3schools"));
</script>
</body>
</html>
how to find the position of the first occurence of a specified value in a string.
<html>
<body>
<script type="text/javascript">
document.write(str.indexof("Hello")+"<br/>");
document.write(str.indexof("World")+"<br/>");
document.write(str.indexof("world")+"<br/>");
</script>
</body>
</html>
No comments:
Post a Comment