String() Object : Introduction : String JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » String » Introduction »

 

String() Object
















Strings are declared by placing the characters between a pair of double quotes (" ") or single quotes ('').

JavaScript interprets single quotes as part of the string if the single quotes are inside a pair of double quotes.

JavaScript interprets double quotes as part of the string if the double quotes are inside a pair of single quotes.

Or, you will you need to use escape sequences.

Syntax to create String object








var variable = new String(string);
    "string"



The String() object is one of the core JavaScript objects.

Instances are created when a program constructs an instance using the new keyword and passing it the String() object.

Properties and Methods Used by the String Object







































































































































Method/Property Description
anchor() Creates an instance of the
big() Converts the string into an instance of the tag.
blink() Converts the string into an instance of the tag.
bold() Converts the string into an instance of the tag.
charAt() Returns the character at the index passed to the method.
charCodeAt() Returns the ISO-Latin-1 number of the character at the index passed to the method.
concat() Concatenates the two strings passed to return a new string. This method was added in JavaScript 1.2.
fixed() Converts the string into an instance of the , fixed pitch font tag.
fontcolor() Sets the COLOR attribute of an instance of the tag.
fontsize() Sets the SIZE attribute of an instance of the tag.
fromCharCode() Returns the string value of the ISO-Latin-1 number passed to the method.
indexOf() Returns the index of the first occurrence of the string passed to the method within an instance of a String object.
italics() Converts the string into an instance of the tag.
lastIndexOf() Returns the index of the last occurrence of the string passed to the method within an instance of a String object.
link() Converts the string into an instance of the
match() Returns an array containing the matches found based on the regular expression passed to the method.
replace() Performs a search and replace, using the regular expression and replace string passed to the method, on the instance of a String that calls it.
search() Returns the index location of the match found in the string passed to the method. A -1 is returned if the string is not found.
slice() Returns the string between the beginning and ending index passed to the method. If a negative number is passed, the index is referenced from the end of the string passed.
small() Converts the string into an instance of the tag.
split() Returns the string split into segments defined by the string and instance limit passed to the method.
strike() Converts the string into an instance of the tag.
sub() Converts the string into an instance of the tag.
substr() Returns the string beginning with the indexed location and number of characters to return. If a negative number is passed, the index is referenced from the end of the string passed.
substring() Returns the string between the beginning and ending index passed to the method.
sup() Converts the string into an instance of the tag.
toLowerCase() Converts all the characters in the string to lowercase.
toSource() Returns the string representation of the String passed.
toString() Returns the characters passed as type string.
toUpperCase() Converts all the characters in the string to uppercase.
length Returns the length of the string.
prototype Provides the ability for a programmer to add properties to instances of the String object.















<html>
    <head>
      <title>Examples of the String Object</title>
    <script language="JavaScript1.1">
    <!--
    function openWin(){
      var myWin = open("""","width=450,height=200");
      var myString = new String("Hello, World!");

      myWin.document.write("Original String, " + myString);
      myWin.document.write(" has " + myString.length + " characters.<br>");
      myWin.document.write("Big: " + myString.big() "<br>");
      myWin.document.write("Small: " + myString.small() "<br>");
      myWin.document.write("Blinking: " + myString.blink() "<br>");
      myWin.document.write("Italics: " + myString.italics() "<br>");
      myWin.document.write("Convert to Lower: " + myString.toLowerCase());
      myWin.document.write("<br>");
      myWin.document.write("Convert to Upper: " + myString.toUpperCase());
      myWin.document.write("<br>");
      myWin.document.close();
    }
    -->
    </script>
    </head>
    <body>
    <form name="myForm">
    <input type=BUTTON value="Click to Process" name="myButton" onClick="openWin()">
    </form>
    </body>
    </html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo String
» Introduction