Home arrow JavaScript arrow Page 2 - JavaScript Objects: More on String Methods
JAVASCRIPT

JavaScript Objects: More on String Methods


Welcome back to my series covering JavaScript Objects. In the last issue we discussed the Object String properties and some of the Object String methods. In this episode we will continue our discussion of the Object String methods and how to use them.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
January 22, 2008
TABLE OF CONTENTS:
  1. · JavaScript Objects: More on String Methods
  2. · The CharAt() Method
  3. · Working with the ConCat() Method
  4. · The FontColor() Method
  5. · FromCharCode() Method
  6. · The LastIndexOf() Method

print this article
SEARCH DEVARTICLES

JavaScript Objects: More on String Methods - The CharAt() Method
(Page 2 of 6 )

If you want to print a character in a specific location in a string, you can use the CharAt() method. No, not the carat you nut. We're not trying to improve your vision. That's what the gamma radiation from your monitor is for.

Here is program that uses the CharAt() method:


<html>

<body>


<script type="text/javascript">


var astring="Are you guys nerds?"


document.write(astring)

document.write("<br /><br />The fourth letter is: " + astring.charAt(4) + "<br />")

document.write("The third letter is: " + astring.charAt(2) + "<br />")

document.write("The twelfth letter is: " + astring.charAt(11))


</script>


</body>

</html>

The above code would display this:

  Are you guys nerds?

  The fourth letter is: y
  The third letter is: e
  The twelfth letter is: s

The CharCodeAt() Method

If you wanted to see the Unicode results of the preceding programming example (and let's face it you party animal, you know you want to), you could use the CharCodeAt() method. Wanna see this bad boy at work? Well here it is: BAM!


<html>

<body>


<script type="text/javascript">


var astring="Are you guys nerds?"

document.write(astring)

document.write("<br /><br />The Unicode for the fourth letter is: " + astring.charCodeAt(4) + "<br />")

document.write("The Unicode for the third letter is: " + astring.charCodeAt(2) + "<br />")

document.write("The Unicode for the twelfth letter is: " + astring.charCodeAt(11))


</script>


</body>

</html>

This program works like the previous program, except now it is returning the Unicode value of the characters instead. The result is this:

  Are you guys nerds?

  The Unicode for the fourth letter is: 121
  The Unicode for the third letter is: 101
  The Unicode for the twelfth letter is: 115

And that's my way of calling you guys nerds in Unicode. You got taken to the Pwn Shop. 


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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