Navigator 2.0, Internet Explorer 3.0; enhanced in Navigator 3.0
new String(value) Navigator 3.0 only
The initial value of the String object being created. This argument will be converted to a string, if necessary.
A newly created String object that holds the string value, or the string representation of value.
The number of characters in the string.
Return a copy of the string, in an <A NAME=> environment.
Return a copy of the string, in a <BIG> environment.
Return a copy of the string, in a <BLINK> environment.
Return a copy of the string, in a <B> environment.
Extract the character at a given position from a string.
Return a copy of the string, in a <TT> environment.
Return a copy of the string, in a <FONT COLOR=> environment.
Return a copy of the string, in a <FONT SIZE=> environment.
Search the string for a character or substring.
Return a copy of the string, in a <I> environment.
Search the string backwards for a character or substring.
Return a copy of the string, in a <A HREF=> environment.
Return a copy of the string, in a <SMALL> environment.
Convert a string to an array of strings, using a specified delimiter character.
Return a copy of the string, in a <STRIKE> environment.
Return a copy of the string, in a <SUB> environment.
Extract a substring of a string.
Return a copy of the string, in a <SUP> environment.
Return a copy of the string, with all characters converted to lower case.
Return a copy of the string, with all characters converted to upper case.
Strings are a basic data type in JavaScript. The String object type exists to provide methods for operating on string values. The length property of a String object specifies the number of characters in the string. The String class defines a number of methods, most of which simply make a copy of the string with HTML tags added before and after. Other methods, however, perform more interesting functions: extracting a character or a substring from the string, or searching for a character or a substring, for example.
The string datatype and the String object are not the same. In Navigator 2.0, however, they are indistinguishable. In Navigator 3.0, you can use the typeof operator to distinguish them (a string has type "string" and a String object has type "object") but you can also use them interchangeably. The reason that string values and String objects can be used interchangeably is that JavaScript converts between these two types whenever necessary. When you invoke a String object method on a string value (which is not an object and cannot have methods), JavaScript converts that value to a temporary String object, allowing the method to be invoked. This temporary String object is not available to the program.
In Navigator 3.0, you can use the String object constructor method to create String objects that are not temporary, and that can actually be used by your programs. It is rarely, if ever, necessary to do this, but if you do, the String object you create can be used interchangeably with a string value. When an object is used where a string value is required, the object's toString() method is automatically invoked by JavaScript to convert the object to a string. If the object is a String object, the resulting value will be the string value that is required.
A number of the String methods are used for creating HTML:
link_text =index.html "My Home Page".bold(); document.write(link_text.link("http://www.djf.com/~david"));
The code above embeds the following string into the HTML document that is currently being parsed:
<A HREF="http://www.djf.com/~david"><B>My Home Page</B></A>
Other methods of the String object perform more interesting functions. The following code, for example, extracts the 3rd through 5th characters of a string and converts them to uppercase letters:
s.substring(2,5).toUpperCase();
file: /Techref/language/JAVA/SCRIPT/definitive/refp_354.htm, 11KB, , updated: 2019/10/14 15:00, local time: 2024/11/26 20:03,
3.149.23.123:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://sxlist.com/techref/language/JAVA/SCRIPT/definitive/refp_354.htm"> [Chapter 21] Reference: String</A> |
Did you find what you needed? |
Welcome to sxlist.com!sales, advertizing, & kind contributors just like you! Please don't rip/copy (here's why Copies of the site on CD are available at minimal cost. |
Welcome to sxlist.com! |
.