Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> JavaScript >> Snippet

08 Strings


Strings are objects
String positions are zero based (leftmost character is 0)

x = new String ( "Yes" )        //both of these are equivalent
x = "yes"     //creates object just like above.  x has properties/methods of string object

Double quotes ( ") and single quotes (') are interchangeable

String concatention example ----------------------------------------
a = b + c + d;
document.writeln(bold_tech + "<br>" );



Escape character (backslash) -----------------------------------
\n     // newline
\t    // tab
\ "   // double quote
\ '   // single quote
\\   // backslash
use inside quotes or where no keyboard equivalent existis

Example of using escape character :
x = "my name is \"mary\", what is yours"      // puts "mary" into the string


String property examples ---------------------------------------------
size = x.length  
size = "yes" .length  
size = prompt( "Enter" ).length 
size = MyFunction().length 

Applying multiple methods -----------------------------------------
MyString.italics().bold().fontcolor( "red" )


String Object Properties and Methods --------------------

Properties :
  length   //number of characters in the string
  prototypes

Methods (grouped by type of function provided) :
 Formatting
       anchor()
       big()
       blink()
       bold()
       fixed()
       fontcolor()
       fontsize()
       italics()
       link()
       small()
       strike()
       sub()
       sup()
  Substrings (find)
       indexOf()
       lastIndexOf()
  Substrings (extract)
       charAt()
       slice()
       substr()
       charCodeAt()
       split()
       substring()
  RegExpression
       match()
       replac e()
       search()
  Other
       concat()
       toLowerCase()
       fromCharCode()
       toUpperCase()