JavaScript string object

JavaScript string object we can use with its different properties and methods to get various string formats and string types. We will discuss with some examples for better understanding.
Let us first declare a new string object like this.

<script type="text/javascript">
my_string= new String("Welcome to plus2net.com");
</script>

Length property to get the length of the string

It gives the total length of the string including blank spaces present in a string.

document.write(my_string.length);
Output: 23

Making the string Bold

document.write(my_string.bold());

Declaring the font size of the string

document.write(my_string.fontsize(6));

Making the string blink ( not work in IE )

document.write(my_string.blink());

Making TT type font with fixed

document.write(my_string.fixed());

Making the font color of the string

document.write(my_string.fontcolor("blue"));

Changing to Italic font

document.write(my_string.italics());

Adding a link to the string by link

document.write(my_string.link("http://www.plus2net.com"));

Making the font style strike out

Demo script using strike property
document.write(my_string.strike());

Getting a substring with start and end points

document.write(my_string.substring(10,15));

Making sub script

document.write(my_string.sub());

Be the first to post comment on this article :


Google+

Post Comment This is for short comments only. Use the forum for more discussions.







OPINION POLL

What is the most important factor of a web site
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer