Home arrow JavaScript arrow Page 5 - JavaScript Objects: Finishing Strings
JAVASCRIPT

JavaScript Objects: Finishing Strings


In the last tutorial we continued our discussion on String Objects in JavaScript. Hopefully we will wrap it up in this episode. We left off with the Match() method, which allowed us to search a string and return the same string if it was present in our variable, or return a null value if it was not. We will pick back up with the Replace() method.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
January 28, 2008
TABLE OF CONTENTS:
  1. · JavaScript Objects: Finishing Strings
  2. · The Replace() Method
  3. · The Search() Method
  4. · The Slice() Method
  5. · The Strike(), Sub(), Small() and Sup() Methods
  6. · The ToLowerCase() and ToUpperCase Methods

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
JavaScript Objects: Finishing Strings - The Strike(), Sub(), Small() and Sup() Methods
(Page 5 of 6 )

The Strike(), Sub(), Small(), and Sup() Methods display a string with a striking line through it, create a subscript, create small text, and create a superscript, respectively. Here they are in code:


<html>

<body>


<script type="text/javascript">


var wordup="Word to ya Motha!"


document.write("<p>This is an example of Small: " + wordup.small() + "</p>")


document.write("<p>This is an example of Strike: " + wordup.strike() + "</p>")

document.write("<p>This is an example of Subscript: " + wordup.sub() + "</p>")

document.write("<p>This is an example of Superscript: " + wordup.sup() + "</p>")


</script>


</body>

</html>

Here is the result:

  This is an example of Small: Word to ya Motha!

  This is an example of Strike: Word to ya Motha!

  This is an example of Subscript: Word to ya Motha!

  This is an example of Superscript: Word to ya Motha!

The SubStr() Method

The SubStr() Method extracts characters from a string, based on the range you specify.


<html>

<body>


<script type="text/javascript">


var str="a b c d e f g h i j k l m n o p q r s t u v w x y z"


document.write(str.substr(0,5))


</script>


</body>

</html>

This code creates a variable that stores the alphabet. We then search that variable and and extract the characters from the 0-5 position (including spaces), which returns: a b c. If we had not included spaces in the string, it would have returned: abcde.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials