1. Technology

Your suggestion is on its way!

An email with a link to:

http://javascript.about.com/library/blstr1.htm

was emailed to:

Thanks for sharing About.com with others!

Basic String Method Reference

Join the Discussion

Questions? Comments?

Related Resources

Tutorial Advanced Methods

The String object holds useful methods for manipulating the character strings you are using within your javascript. These methods can be substituted in your javascript wherever character values are allowed. The String object is pre-defined so does not need to be defined before use. The following simple methods are supported by the String object in all versions of Javascript:

  • anchor(section_name) puts the string between <a name=> tags
  • big() puts the string between <big> tags
  • blink() puts the string between <blink> tags
  • bold() puts the string between <bold> tags
  • charAt(number) selects the single character at the specified position within the string
  • fixed() puts the string between <tt> tags
  • fontcolor(colour) puts the string between <font color=> tags
  • fontsize(number) puts the string between <font size=> tags
  • indexOf(substring) finds the position where the specified substring starts
  • italics() puts the string between <i> tags
  • lastIndexOf(substring) finds the last occurrence of the substring within the string
  • link(address) puts the string between <a href=> tags
  • small() puts the string between <small> tags
  • strike() puts the string between <strike> tags
  • sub() puts the string between <sub> tags
  • substring(start,end) gets the specified part of the string
  • sup() puts the string between <sup> tags
  • toLowerCase() convert the string to lowercase
  • toUpperCase() convert the string to uppercase

Many of these methods are equivalent to placing the string between the appropriate tags.
For example document.write(mystring.href("index.html"); is equivalent to
document.write('<a href="index.html">' + mystring + '<\/a>');.
Some of these methods are equivalent to surrounding the string with tags that are no longer supported by the latest xhtml version.

©2014 About.com. All rights reserved.