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"> |
---|
29 | <td class="micon"><a class="exi" href="#expand"> </a></td> |
---|
30 | <td class="sig"> |
---|
31 | <a id="String-escape"></a> |
---|
32 | <b>escape</b>( <code>String string</code> ) : String <div class="mdesc"> |
---|
33 | <div class="short"><static> Escapes the passed string for ' and \</div> |
---|
34 | <div class="long"> |
---|
35 | <static> Escapes the passed string for ' and \ <div class="mdetail-params"> |
---|
36 | <strong>Parameters:</strong> |
---|
37 | <ul><li><code>string</code> : String<div class="sub-desc">The string to escape</div></li> </ul> |
---|
38 | <strong>Returns:</strong> |
---|
39 | <ul> |
---|
40 | <li><code>String</code><div class="sub-desc">The escaped string</div></li> |
---|
41 | </ul> |
---|
42 | </div> |
---|
43 | </div> |
---|
44 | </div> |
---|
45 | </td> |
---|
46 | <td class="msource">String</td> |
---|
47 | </tr> |
---|
48 | <tr class="method-row alt expandable"> |
---|
49 | <td class="micon"><a class="exi" href="#expand"> </a></td> |
---|
50 | <td class="sig"> |
---|
51 | <a id="String-format"></a> |
---|
52 | <b>format</b>( <code>String string</code>, <code>String value1</code>, <code>String value2</code> ) : String <div class="mdesc"> |
---|
53 | <div class="short"><static> Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the token...</div> |
---|
54 | <div class="long"> |
---|
55 | <static> 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>'<div class="{0}">{1}</div>'</em>, cls, text); |
---|
59 | // s now contains the string: <em>'<div class="my-class">Some text</div>'</em></code></pre> <div class="mdetail-params"> |
---|
60 | <strong>Parameters:</strong> |
---|
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> |
---|
62 | <strong>Returns:</strong> |
---|
63 | <ul> |
---|
64 | <li><code>String</code><div class="sub-desc">The formatted string</div></li> |
---|
65 | </ul> |
---|
66 | </div> |
---|
67 | </div> |
---|
68 | </div> |
---|
69 | </td> |
---|
70 | <td class="msource">String</td> |
---|
71 | </tr> |
---|
72 | <tr class="method-row expandable"> |
---|
73 | <td class="micon"><a class="exi" href="#expand"> </a></td> |
---|
74 | <td class="sig"> |
---|
75 | <a id="String-leftPad"></a> |
---|
76 | <b>leftPad</b>( <code>String string</code>, <code>Number size</code>, <span class="optional" title="Optional">[<code>String char</code>]</span> ) : String <div class="mdesc"> |
---|
77 | <div class="short"><static> Pads the left side of a string with a specified character. This is especially useful |
---|
78 | for normalizing ...</div> |
---|
79 | <div class="long"> |
---|
80 | <static> 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"> |
---|
84 | <strong>Parameters:</strong> |
---|
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> |
---|
86 | <strong>Returns:</strong> |
---|
87 | <ul> |
---|
88 | <li><code>String</code><div class="sub-desc">The padded string</div></li> |
---|
89 | </ul> |
---|
90 | </div> |
---|
91 | </div> |
---|
92 | </div> |
---|
93 | </td> |
---|
94 | <td class="msource">String</td> |
---|
95 | </tr> |
---|
96 | <tr class="method-row alt expandable"> |
---|
97 | <td class="micon"><a class="exi" href="#expand"> </a></td> |
---|
98 | <td class="sig"> |
---|
99 | <a id="String-toggle"></a> |
---|
100 | <b>toggle</b>( <code>String value</code>, <code>String other</code> ) : String <div class="mdesc"> |
---|
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> |
---|
103 | <div class="long"> |
---|
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"> |
---|
113 | <strong>Parameters:</strong> |
---|
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> |
---|
115 | <strong>Returns:</strong> |
---|
116 | <ul> |
---|
117 | <li><code>String</code><div class="sub-desc">The new value</div></li> |
---|
118 | </ul> |
---|
119 | </div> |
---|
120 | </div> |
---|
121 | </div> |
---|
122 | </td> |
---|
123 | <td class="msource">String</td> |
---|
124 | </tr> |
---|
125 | <tr class="method-row expandable"> |
---|
126 | <td class="micon"><a class="exi" href="#expand"> </a></td> |
---|
127 | <td class="sig"> |
---|
128 | <a id="String-trim"></a> |
---|
129 | <b>trim</b>() : String <div class="mdesc"> |
---|
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> |
---|
132 | <div class="long"> |
---|
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"> |
---|
137 | <strong>Parameters:</strong> |
---|
138 | <ul><li>None.</li> </ul> |
---|
139 | <strong>Returns:</strong> |
---|
140 | <ul> |
---|
141 | <li><code>String</code><div class="sub-desc">The trimmed string</div></li> |
---|
142 | </ul> |
---|
143 | </div> |
---|
144 | </div> |
---|
145 | </div> |
---|
146 | </td> |
---|
147 | <td class="msource">String</td> |
---|
148 | </tr> |
---|
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> |
---|