⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.html

📁 javascript 1.5规范
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<HTML><HEAD>        <META NAME="keywords" CONTENT="electronic commerce, ecommerce, ebusiness, e-business, e-commerce, enterprise software, net economy, Netscape, Sun Microsystems, Sun-Netscape Alliance, iPlanet, internet software">        <META NAME="description" CONTENT="The Sun-Netscape Alliance, a strategic alliance formed by America Online and Sun Microsystems, Inc., is delivering iPlanet e-commerce software and enterprise solutions that enable companies to compete successfully in the Net Economy">	<META HTTP-EQUIV="Content-Type" content="text/html; charset=ISO-8859-1">	<META NAME="TEMPLATEBASE" CONTENT="Authored in FrameMaker. Converted to HTML in WebWorks Publisher 2000. manual wdt 1.5">	<META NAME="LASTUPDATED" CONTENT="09/28/00 13:15:58">	<TITLE> Core JavaScript Reference 1.5:  </TITLE></HEAD><BODY TEXT="#000000" LINK="#666699" VLINK="#666699" ALINK="#333366" BGCOLOR="#FFFFFF"><MAINCONTENT><NAVIGATIONCONTENT>   <TABLE WIDTH="100%" BORDER="0" CELLSPACING="4">      <TR>         <TD VALIGN="TOP">            <b><a href="regexp.html"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Previous</a></FONT>&nbsp;&nbsp;&nbsp;&nbsp;</b><a href="contents.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Contents</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;<a href="ix.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Index</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;<a href="sun.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Next</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;         </TD>     </TR>      <TR>         <TD VALIGN="TOP" ALIGN="RIGHT" BGCOLOR="#CCCCCC">            <FONT FACE="Arial, Helvetica, sans-serif" COLOR="#000000" SIZE="2"><B>             Core JavaScript Reference 1.5</B></FONT>         </TD>      </TR>      <TR>   </TABLE>   <BR></NAVIGATIONCONTENT><BOOKCONTENT>   <blockquote><BR><BR>      <BR><BR><P><A NAME="1193137"> </A><A NAME="String"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="5"><B><zrefhead1>String</zrefhead1></B></FONT><P><A NAME="1193173"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>An object representing a series of characters in a string. <BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT><BR><BR>  <TR>    <TD VALIGN=TOP COLSPAN=2 ROWSPAN=1><P><A NAME="1193141"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>Core object</I></ztabletext></FONT></TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1193145"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>Implemented in</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193147"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.0: Create a <FONT FACE="courier, couriernew, monospaced size">String</FONT> object only by quoting characters.</ztabletext></FONT><P><A NAME="1199831"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext></ztabletext></FONT><P><A NAME="1199852"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.1, NES 2.0: added <FONT FACE="courier, couriernew, monospaced size">String</FONT> constructor; added <FONT FACE="courier, couriernew, monospaced size">prototype</FONT> property; added <A HREF="string.html#1194452"  >split</A> method; added ability to pass strings among scripts in different windows or frames (in previous releases, you had to add an empty string to another window's string to refer to it).</ztabletext></FONT><P><A NAME="1199832"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext></ztabletext></FONT><P><A NAME="1199861"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.2, NES 3.0: added <A HREF="string.html#1196678"  >concat</A>, <A HREF="string.html#1205239"  >match</A>, <A HREF="string.html#1194258"  >replace</A>, <A HREF="string.html#1194332"  >search</A>, <A HREF="string.html#1194366"  >slice</A>, and <A HREF="string.html#1194618"  >substr</A> methods.</ztabletext></FONT><P><A NAME="1193172"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext></ztabletext></FONT><P><A NAME="1199870"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.3: added <A HREF="string.html#1194796"  >toSource</A> method; changed <A HREF="string.html#1196647"  >charCodeAt</A>, <A HREF="string.html#1225094"  >fromCharCode</A>, and <A HREF="string.html#1194258"  >replace</A> methods.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1203114"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>ECMA version</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1203116"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>ECMA-262</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></zparagraph></FONT><P><BR><A NAME="1199477"> </A><A NAME="Created by"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Created by</zrefheader></B></FONT><BR><A NAME="1193175"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The <FONT FACE="courier, couriernew, monospaced size">String</FONT> constructor:</zparagraph></FONT><P><A NAME="1193176"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>new String(<I>string</I>)</zcodeline></FONT><P><BR><A NAME="1193177"> </A><A NAME="Parameters"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Parameters</zrefheader></B></FONT><BR><A NAME="1193183"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT><BR><BR>  <TR>    <TD VALIGN=TOP><A NAME="1193180"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>string</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193182"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Any string.</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></zparagraph></FONT><P><BR><A NAME="1193184"> </A><A NAME="Description"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Description</zrefheader></B></FONT><BR><A NAME="1228794"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The <FONT FACE="courier, couriernew, monospaced size">String</FONT> object is a wrapper around the string primitive data type. Do not confuse a string literal with the <FONT FACE="courier, couriernew, monospaced size">String</FONT> object. For example, the following code creates the string literal <FONT FACE="courier, couriernew, monospaced size">s1</FONT> and also the <FONT FACE="courier, couriernew, monospaced size">String</FONT> object <FONT FACE="courier, couriernew, monospaced size">s2</FONT>:</zparagraph></FONT><P><A NAME="1228795"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>s1 = "foo" // creates a string literal value<br>s2 = new String("foo") // creates a String object</zcodeline></FONT><P><A NAME="1228796"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>You can call any of the methods of the <FONT FACE="courier, couriernew, monospaced size">String</FONT> object on a string literal value&#151;JavaScript automatically converts the string literal to a temporary <FONT FACE="courier, couriernew, monospaced size">String</FONT> object, calls the method, then discards the temporary <FONT FACE="courier, couriernew, monospaced size">String</FONT> object. You can also use the <FONT FACE="courier, couriernew, monospaced size">String.length</FONT> property with a string literal.</zparagraph></FONT><P><A NAME="1237619"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>You should use string literals unless you specifically need to use a <FONT FACE="courier, couriernew, monospaced size">String</FONT> object, because <FONT FACE="courier, couriernew, monospaced size">String</FONT> objects can have counterintuitive behavior. For example:</zparagraph></FONT><P><A NAME="1237620"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>s1 = "2 + 2" // creates a string literal value<br>s2 = new String("2 + 2") // creates a String object<br>eval(s1) &nbsp;&nbsp;&nbsp;&nbsp;// returns the number 4<br>eval(s2) &nbsp;&nbsp;&nbsp;&nbsp;// returns the string "2 + 2"</zcodeline></FONT><P><A NAME="1193186"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>A string can be represented as a literal enclosed by single or double quotation marks; for example, "Netscape" or `Netscape'.</zparagraph></FONT><P><A NAME="1228443"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>You can convert the value of any object into a string using the top-level <A HREF="toplev.html#1064506"  >String</A> function.</zparagraph></FONT><P><BR><A NAME="1193187"> </A><A NAME="Property Summary"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Property Summary</zrefheader></B></FONT><BR><A NAME="1193207"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT><BR><BR>  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1193190"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Property</ztablehead></B></FONT></TH>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1193192"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Description</ztablehead></B></FONT></TH>  </DIV></TR>  <TR>    <TD VALIGN=TOP><A NAME="1214599"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline><A HREF="string.html#1214362"  >constructor</A></zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1214601"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Specifies the function that creates an object's prototype.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193197"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline><A HREF="string.html#1193437"  >length</A></zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193199"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Reflects the length of the string.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193204"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline><A HREF="string.html#1193463"  >prototype</A></zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193206"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Allows the addition of properties to a <FONT FACE="courier, couriernew, monospaced size">String</FONT> object.</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></zparagraph></FONT><P><BR><A NAME="1193208"> </A><A NAME="Method Summary"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Method Summary</zrefheader></B></FONT><BR><A NAME="1193420"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT><BR><BR>  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1193211"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Method</ztablehead></B></FONT></TH>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1193213"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Description</ztablehead></B></FONT></TH>  </DIV></TR>  <TR>    <TD VALIGN=TOP><A NAME="1193218"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline><A HREF="string.html#1196382"  >anchor</A></zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193220"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Creates an HTML anchor that is used as a hypertext target.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193225"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline><A HREF="string.html#1196447"  >big</A></zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193227"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Causes a string to be displayed in a big font as if it were in a <FONT FACE="courier, couriernew, monospaced size">BIG</FONT> tag.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193232"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline><A HREF="string.html#1196495"  >blink</A></zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193234"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Causes a string to blink as if it were in a <FONT FACE="courier, couriernew, monospaced size">BLINK</FONT> tag.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193239"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline><A HREF="string.html#1196546"  >bold</A></zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193241"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Causes a string to be displayed as if it were in a <FONT FACE="courier, couriernew, monospaced size">B</FONT> tag.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193246"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline><A HREF="string.html#1196596"  >charAt</A></zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -