SunQuest
 
       JavaScript
  Home arrow JavaScript arrow Page 5 - JavaScript Objects: More on String Methods
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

JavaScript Objects: More on String Methods
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-01-22

    Table of Contents:
  • JavaScript Objects: More on String Methods
  • The CharAt() Method
  • Working with the ConCat() Method
  • The FontColor() Method
  • FromCharCode() Method
  • The LastIndexOf() Method

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    JavaScript Objects: More on String Methods - FromCharCode() Method


    (Page 5 of 6 )

    You use the FromCharCode() method to translate Unicode to text. Here is the alphabet written in Unicode. Yep go ahead. Nerd it up.


    <html>

    <body>


    <script type="text/javascript">

    document.write("Here is the alphabet in Unicode <br /> <br />")

    document.write(String.fromCharCode(65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90))


    </script>


    </body>

    </html>

    Here is the result:

      Here is the alphabet in Unicode

      ABCDEFGHIJKLMNOPQRSTUVWXYZ

    Full Unicode charts are freely available on the web and are quite extensive.

    The IndexOf() Method

    The IndexOf() method is useful if you wish to know where a string within a string begins (its position in the string rather). Behold my next example, puny mortal:


    <html>

    <body>


    <script type="text/javascript">


    var myfeelings="I love Gorillas!"

    document.write(myfeelings.indexOf("I") + "<br />")

    document.write(myfeelings.indexOf("love") + "<br />")

    document.write(myfeelings.indexOf("to eat") + "<br />")

    document.write(myfeelings.indexOf("Gorillas"))


    </script>


    </body>

    </html>

    This creates a variable named myfeelings and stores the text "I love Gorillas" in it. It then checks for the position of the word "I," which it finds, and prints out its position (positions begin with 0). Then it looks for the word "love" and finds it begins at the 2 position (the l that starts the word is the second character in the string). Next it looks for the text "to eat" in the variable, and does not find it. Because it is not in the string, and therefore its position cannot be found, it results in the number -1. Any time info is not found, it will return -1.

    Lastly, it searches for the word "Gorillas" (my all time favorite word) and finds it located in position 7. Here are the results of the program:

      0
      2
      -1
      7

    Note that the IndexOf() method is case-sensitive. If I had told it to find "gorillas" in the string, it would not have worked and returned a -1 for its position.

    More JavaScript Articles
    More By James Payne


       · Thanks for digging on my article about Javascript String Methods. In this enticing...
     

    JAVASCRIPT ARTICLES

    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps
    - Adding Zoom Controls to Yahoo! Maps
    - Working with Yahoo! Maps
    - Building Image Zooming Controls with the DOM...
    - Working with Multiple Graphics for a Zoom Ap...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway