String() Object : Introduction « String « JavaScript Tutorial

JavaScript Tutorial
1. Language Basics
2. Operators
3. Statement
4. Development
5. Number Data Type
6. String
7. Function
8. Global
9. Math
10. Form
11. Array
12. Date
13. Dialogs
14. Document
15. Event
16. Location
17. Navigator
18. Screen
19. Window
20. History
21. HTML Tags
22. Style
23. DOM Node
24. Drag Drop
25. Object Oriented
26. Regular Expressions
27. XML
28. GUI Components
29. Dojo toolkit
30. jQuery
31. Animation
32. MS JScript
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
JavaScript Tutorial » String » Introduction 
6. 1. 2. 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/PropertyDescription
anchor()Creates an instance of the tag with the NAME attribute set to the string passed to the method.
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 tag and sets the HREF attribute with the URL that is passed to the method.
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.
lengthReturns the length of the string.
prototypeProvides 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>
6. 1. Introduction
6. 1. 1. The String Type
6. 1. 2. String() Object
6. 1. 3. Special Characters (escape sequence)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.