commit extjs-2.2.1
[extjs.git] / docs / output / String.html
1         <div class="body-wrap">
2         <div class="top-tools">
3             <a class="inner-link" href="#String-props"><img src="../resources/images/default/s.gif" class="item-icon icon-prop">Properties</a>
4             <a class="inner-link" href="#String-methods"><img src="../resources/images/default/s.gif" class="item-icon icon-method">Methods</a>
5             <a class="inner-link" href="#String-events"><img src="../resources/images/default/s.gif" class="item-icon icon-event">Events</a>
6                         <a class="bookmark" href="../docs/?class=String"><img src="../resources/images/default/s.gif" class="item-icon icon-fav">Direct Link</a>
7         </div>
8                 <h1>Class String</h1>
9         <table cellspacing="0">
10             <tr><td class="label">Package:</td><td class="hd-info">Global</td></tr>
11             <tr><td class="label">Defined In:</td><td class="hd-info"><a href="../src/Ext.js" target="_blank">Ext.js</a></td></tr>
12             <tr><td class="label">Class:</td><td class="hd-info">String</td></tr>
13                                     <tr><td class="label">Extends:</td><td class="hd-info">Object</td></tr>
14                     </table>
15         <div class="description">
16             These functions are available as static methods on the JavaScript String object.        </div>
17         
18         <div class="hr"></div>
19                 <a id="String-props"></a>
20         <h2>Public Properties</h2>
21         <div class="no-members">This class has no public properties.</div>        <a id="String-methods"></a>
22         <h2>Public Methods</h2>
23                 <table cellspacing="0" class="member-table">
24             <tr>
25                 <th class="sig-header" colspan="2">Method</th>
26                 <th class="msource-header">Defined By</th>
27             </tr>
28                 <tr class="method-row expandable">\r
29         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
30         <td class="sig">\r
31         <a id="String-escape"></a>\r
32             <b>escape</b>(&nbsp;<code>String string</code>&nbsp;) : String            <div class="mdesc">\r
33                         <div class="short">&lt;static&gt; Escapes the passed string for ' and \</div>\r
34             <div class="long">\r
35                 &lt;static&gt; Escapes the passed string for ' and \    <div class="mdetail-params">\r
36         <strong>Parameters:</strong>\r
37         <ul><li><code>string</code> : String<div class="sub-desc">The string to escape</div></li>        </ul>\r
38         <strong>Returns:</strong>\r
39         <ul>\r
40             <li><code>String</code><div class="sub-desc">The escaped string</div></li>\r
41         </ul>\r
42     </div>\r
43                 </div>\r
44                         </div>\r
45         </td>\r
46         <td class="msource">String</td>\r
47     </tr>\r
48         <tr class="method-row alt expandable">\r
49         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
50         <td class="sig">\r
51         <a id="String-format"></a>\r
52             <b>format</b>(&nbsp;<code>String string</code>, <code>String value1</code>, <code>String value2</code>&nbsp;) : String            <div class="mdesc">\r
53                         <div class="short">&lt;static&gt; Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the token...</div>\r
54             <div class="long">\r
55                 &lt;static&gt; Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens.  Each
56 token must be unique, and must increment in the format {0}, {1}, etc.  Example usage:
57 <pre><code>var cls = <em>'my-class'</em>, text = <em>'Some text'</em>;
58 <b>var</b> s = String.format(<em>'&lt;div class="{0}">{1}&lt;/div>'</em>, cls, text);
59 // s now contains the string: <em>'&lt;div class="my-class">Some text&lt;/div>'</em></code></pre>    <div class="mdetail-params">\r
60         <strong>Parameters:</strong>\r
61         <ul><li><code>string</code> : String<div class="sub-desc">The tokenized string to be formatted</div></li><li><code>value1</code> : String<div class="sub-desc">The value to replace token {0}</div></li><li><code>value2</code> : String<div class="sub-desc">Etc...</div></li>        </ul>\r
62         <strong>Returns:</strong>\r
63         <ul>\r
64             <li><code>String</code><div class="sub-desc">The formatted string</div></li>\r
65         </ul>\r
66     </div>\r
67                 </div>\r
68                         </div>\r
69         </td>\r
70         <td class="msource">String</td>\r
71     </tr>\r
72         <tr class="method-row expandable">\r
73         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
74         <td class="sig">\r
75         <a id="String-leftPad"></a>\r
76             <b>leftPad</b>(&nbsp;<code>String string</code>, <code>Number size</code>, <span class="optional" title="Optional">[<code>String char</code>]</span>&nbsp;) : String            <div class="mdesc">\r
77                         <div class="short">&lt;static&gt; Pads the left side of a string with a specified character.  This is especially useful
78 for normalizing ...</div>\r
79             <div class="long">\r
80                 &lt;static&gt; Pads the left side of a string with a specified character.  This is especially useful
81 for normalizing number and date strings.  Example usage:
82 <pre><code>var s = String.leftPad(<em>'123'</em>, 5, <em>'0'</em>);
83 // s now contains the string: <em>'00123'</em></code></pre>    <div class="mdetail-params">\r
84         <strong>Parameters:</strong>\r
85         <ul><li><code>string</code> : String<div class="sub-desc">The original string</div></li><li><code>size</code> : Number<div class="sub-desc">The total length of the output string</div></li><li><code>char</code> : String<div class="sub-desc">(optional) The character with which to pad the original string (defaults to empty string " ")</div></li>        </ul>\r
86         <strong>Returns:</strong>\r
87         <ul>\r
88             <li><code>String</code><div class="sub-desc">The padded string</div></li>\r
89         </ul>\r
90     </div>\r
91                 </div>\r
92                         </div>\r
93         </td>\r
94         <td class="msource">String</td>\r
95     </tr>\r
96         <tr class="method-row alt expandable">\r
97         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
98         <td class="sig">\r
99         <a id="String-toggle"></a>\r
100             <b>toggle</b>(&nbsp;<code>String value</code>, <code>String other</code>&nbsp;) : String            <div class="mdesc">\r
101                         <div class="short">Utility function that allows you to easily switch a string between two alternating values.  The passed value
102 is compa...</div>\r
103             <div class="long">\r
104                 Utility function that allows you to easily switch a string between two alternating values.  The passed value
105 is compared to the current string, and if they are equal, the other value that was passed in is returned.  If
106 they are already different, the first value passed in is returned.  Note that this method returns the new value
107 but does not change the current string.
108 <pre><code><i>// alternate sort directions</i>
109 sort = sort.toggle(<em>'ASC'</em>, <em>'DESC'</em>);
110
111 <i>// instead of conditional logic:</i>
112 sort = (sort == <em>'ASC'</em> ? <em>'DESC'</em> : <em>'ASC'</em>);</code></pre>    <div class="mdetail-params">\r
113         <strong>Parameters:</strong>\r
114         <ul><li><code>value</code> : String<div class="sub-desc">The value to compare to the current string</div></li><li><code>other</code> : String<div class="sub-desc">The new value to use if the string already equals the first value passed in</div></li>        </ul>\r
115         <strong>Returns:</strong>\r
116         <ul>\r
117             <li><code>String</code><div class="sub-desc">The new value</div></li>\r
118         </ul>\r
119     </div>\r
120                 </div>\r
121                         </div>\r
122         </td>\r
123         <td class="msource">String</td>\r
124     </tr>\r
125         <tr class="method-row expandable">\r
126         <td class="micon"><a class="exi" href="#expand">&nbsp;</a></td>\r
127         <td class="sig">\r
128         <a id="String-trim"></a>\r
129             <b>trim</b>() : String            <div class="mdesc">\r
130                         <div class="short">Trims whitespace from either end of a string, leaving spaces within the string intact.  Example:
131 var s = '  foo bar  ...</div>\r
132             <div class="long">\r
133                 Trims whitespace from either end of a string, leaving spaces within the string intact.  Example:
134 <pre><code>var s = <em>'  foo bar  '</em>;
135 alert(<em>'-'</em> + s + <em>'-'</em>);         <i>//alerts <em>"- foo bar -"</em></i>
136 alert(<em>'-'</em> + s.trim() + <em>'-'</em>);  //alerts <em>"-foo bar-"</em></code></pre>    <div class="mdetail-params">\r
137         <strong>Parameters:</strong>\r
138         <ul><li>None.</li>        </ul>\r
139         <strong>Returns:</strong>\r
140         <ul>\r
141             <li><code>String</code><div class="sub-desc">The trimmed string</div></li>\r
142         </ul>\r
143     </div>\r
144                 </div>\r
145                         </div>\r
146         </td>\r
147         <td class="msource">String</td>\r
148     </tr>\r
149             </table>
150                 <a id="String-events"></a>
151         <h2>Public Events</h2>
152         <div class="no-members">This class has no public events.</div>
153         </div>