String.html 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='String'>/**
  19. </span> * @class String
  20. *
  21. * `String` is a global object that may be used to construct String instances.
  22. *
  23. * String objects may be created by calling the constructor `new String()`. The `String` object wraps
  24. * JavaScript's string primitive data type with the methods described below. The global function
  25. * `String()` can also be called without new in front to create a primitive string. String literals in
  26. * JavaScript are primitive strings.
  27. *
  28. * Because JavaScript automatically converts between string primitives and String objects, you can call
  29. * any of the methods of the `String` object on a string primitive. JavaScript automatically converts the
  30. * string primitive to a temporary `String` object, calls the method, then discards the temporary String
  31. * object. For example, you can use the `String.length` property on a string primitive created from a
  32. * string literal:
  33. *
  34. * s_obj = new String(s_prim = s_also_prim = &quot;foo&quot;);
  35. *
  36. * s_obj.length; // 3
  37. * s_prim.length; // 3
  38. * s_also_prim.length; // 3
  39. * 'foo'.length; // 3
  40. * &quot;foo&quot;.length; // 3
  41. *
  42. * (A string literal is denoted with single or double quotation marks.)
  43. *
  44. * String objects can be converted to primitive strings with the `valueOf` method.
  45. *
  46. * String primitives and String objects give different results when evaluated as JavaScript. Primitives
  47. * are treated as source code; String objects are treated as a character sequence object. For example:
  48. *
  49. * s1 = &quot;2 + 2&quot;; // creates a string primitive
  50. * s2 = new String(&quot;2 + 2&quot;); // creates a String object
  51. * eval(s1); // returns the number 4
  52. * eval(s2); // returns the string &quot;2 + 2&quot;
  53. * eval(s2.valueOf()); // returns the number 4
  54. *
  55. * # Character access
  56. *
  57. * There are two ways to access an individual character in a string. The first is the `charAt` method:
  58. *
  59. * return 'cat'.charAt(1); // returns &quot;a&quot;
  60. *
  61. * The other way is to treat the string as an array, where each index corresponds to an individual
  62. * character:
  63. *
  64. * return 'cat'[1]; // returns &quot;a&quot;
  65. *
  66. * The second way (treating the string as an array) is not part of ECMAScript 3. It is a JavaScript and
  67. * ECMAScript 5 feature.
  68. *
  69. * In both cases, attempting to set an individual character won't work. Trying to set a character
  70. * through `charAt` results in an error, while trying to set a character via indexing does not throw an
  71. * error, but the string itself is unchanged.
  72. *
  73. * # Comparing strings
  74. *
  75. * C developers have the `strcmp()` function for comparing strings. In JavaScript, you just use the less-
  76. * than and greater-than operators:
  77. *
  78. * var a = &quot;a&quot;;
  79. * var b = &quot;b&quot;;
  80. * if (a &lt; b) // true
  81. * print(a + &quot; is less than &quot; + b);
  82. * else if (a &gt; b)
  83. * print(a + &quot; is greater than &quot; + b);
  84. * else
  85. * print(a + &quot; and &quot; + b + &quot; are equal.&quot;);
  86. *
  87. * A similar result can be achieved using the `localeCompare` method inherited by `String` instances.
  88. *
  89. * &lt;div class=&quot;notice&quot;&gt;
  90. * Documentation for this class comes from &lt;a href=&quot;https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String&quot;&gt;MDN&lt;/a&gt;
  91. * and is available under &lt;a href=&quot;http://creativecommons.org/licenses/by-sa/2.0/&quot;&gt;Creative Commons: Attribution-Sharealike license&lt;/a&gt;.
  92. * &lt;/div&gt;
  93. */
  94. <span id='String-method-constructor'>/**
  95. </span> * @method constructor
  96. * Creates new String object.
  97. * @param {Object} value The value to wrap into String object.
  98. */
  99. //Methods
  100. <span id='String-method-fromCharCode'>/**
  101. </span> * @method fromCharCode
  102. * Returns a string created by using the specified sequence of Unicode values.
  103. *
  104. * This method returns a string and not a `String` object.
  105. *
  106. * Because `fromCharCode` is a static method of `String`, you always use it as `String.fromCharCode()`,
  107. * rather than as a method of a `String` object you created.
  108. *
  109. * Although most common Unicode values can be represented in a fixed width system/with one number (as
  110. * expected early on during JavaScript standardization) and `fromCharCode()` can be used to return a
  111. * single character for the most common values (i.e., UCS-2 values which are the subset of UTF-16 with
  112. * the most common characters), in order to deal with ALL legal Unicode values, `fromCharCode()` alone
  113. * is inadequate. Since the higher code point characters use two (lower value) &quot;surrogate&quot; numbers to
  114. * form a single character, `fromCharCode()` can be used to return such a pair and thus adequately
  115. * represent these higher valued characters.
  116. *
  117. * Be aware, therefore, that the following utility function to grab the accurate character even for
  118. * higher value code points, may be returning a value which is rendered as a single character, but
  119. * which has a string count of two (though usually the count will be one).
  120. *
  121. * // String.fromCharCode() alone cannot get the character at such a high code point
  122. * // The following, on the other hand, can return a 4-byte character as well as the
  123. * // usual 2-byte ones (i.e., it can return a single character which actually has
  124. * // a string length of 2 instead of 1!)
  125. * alert(fixedFromCharCode(0x2F804)); // or 194564 in decimal
  126. *
  127. * function fixedFromCharCode (codePt) {
  128. * if (codePt &gt; 0xFFFF) {
  129. * codePt -= 0x10000;
  130. * return String.fromCharCode(0xD800 + (codePt &gt;&gt; 10), 0xDC00 +
  131. * (codePt &amp; 0x3FF));
  132. * }
  133. * else {
  134. * return String.fromCharCode(codePt);
  135. * }
  136. * }
  137. *
  138. * The following example returns the string &quot;ABC&quot;.
  139. *
  140. * String.fromCharCode(65,66,67)
  141. *
  142. * @param {Number} num1, ..., numN A sequence of numbers that are Unicode values.
  143. * @return {String} String containing characters from encoding.
  144. */
  145. //Properties
  146. <span id='String-property-length'>/**
  147. </span> * @property {Number} length
  148. * Reflects the length of the string.
  149. *
  150. * This property returns the number of code units in the string. UTF-16, the string format used by JavaScript, uses a single 16-bit
  151. * code unit to represent the most common characters, but needs to use two code units for less commonly-used characters, so it's
  152. * possible for the value returned by `length` to not match the actual number of characters in the string.
  153. *
  154. * For an empty string, `length` is 0.
  155. *
  156. * var x = &quot;Netscape&quot;;
  157. * var empty = &quot;&quot;;
  158. *
  159. * console.log(&quot;Netspace is &quot; + x.length + &quot; code units long&quot;);
  160. * console.log(&quot;The empty string is has a length of &quot; + empty.length); // should be 0
  161. */
  162. //Methods
  163. <span id='String-method-charAt'>/**
  164. </span> * @method charAt
  165. * Returns the character at the specified index.
  166. *
  167. * Characters in a string are indexed from left to right. The index of the first character is 0, and
  168. * the index of the last character in a string called `stringName` is `stringName.length - 1`. If the
  169. * index you supply is out of range, JavaScript returns an empty string.
  170. *
  171. * The following example displays characters at different locations in the string &quot;Brave new world&quot;:
  172. *
  173. * var anyString=&quot;Brave new world&quot;;
  174. *
  175. * document.writeln(&quot;The character at index 0 is '&quot; + anyString.charAt(0) + &quot;'&quot;);
  176. * document.writeln(&quot;The character at index 1 is '&quot; + anyString.charAt(1) + &quot;'&quot;);
  177. * document.writeln(&quot;The character at index 2 is '&quot; + anyString.charAt(2) + &quot;'&quot;);
  178. * document.writeln(&quot;The character at index 3 is '&quot; + anyString.charAt(3) + &quot;'&quot;);
  179. * document.writeln(&quot;The character at index 4 is '&quot; + anyString.charAt(4) + &quot;'&quot;);
  180. * document.writeln(&quot;The character at index 999 is '&quot; + anyString.charAt(999) + &quot;'&quot;);
  181. *
  182. * These lines display the following:
  183. *
  184. * The character at index 0 is 'B'
  185. * The character at index 1 is 'r'
  186. * The character at index 2 is 'a'
  187. * The character at index 3 is 'v'
  188. * The character at index 4 is 'e'
  189. * The character at index 999 is ''
  190. *
  191. * The following provides a means of ensuring that going through a string loop always provides a whole
  192. * character, even if the string contains characters that are not in the Basic Multi-lingual Plane.
  193. *
  194. * var str = 'A\uD87E\uDC04Z'; // We could also use a non-BMP character directly
  195. * for (var i=0, chr; i &lt; str.length; i++) {
  196. * if ((chr = getWholeChar(str, i)) === false) {continue;} // Adapt this line at the top of
  197. * each loop, passing in the whole string and the current iteration and returning a variable to
  198. * represent the individual character
  199. * alert(chr);
  200. * }
  201. *
  202. * function getWholeChar (str, i) {
  203. * var code = str.charCodeAt(i);
  204. *
  205. * if (isNaN(code)) {
  206. * return ''; // Position not found
  207. * }
  208. * if (code &lt; 0xD800 || code &gt; 0xDFFF) {
  209. * return str.charAt(i);
  210. * }
  211. * if (0xD800 &lt;= code &amp;&amp; code &lt;= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F
  212. * to treat high private surrogates as single characters)
  213. * if (str.length &lt;= (i+1)) {
  214. * throw 'High surrogate without following low surrogate';
  215. * }
  216. * var next = str.charCodeAt(i+1);
  217. * if (0xDC00 &gt; next || next &gt; 0xDFFF) {
  218. * throw 'High surrogate without following low surrogate';
  219. * }
  220. * return str.charAt(i)+str.charAt(i+1);
  221. * }
  222. * // Low surrogate (0xDC00 &lt;= code &amp;&amp; code &lt;= 0xDFFF)
  223. * if (i === 0) {
  224. * throw 'Low surrogate without preceding high surrogate';
  225. * }
  226. * var prev = str.charCodeAt(i-1);
  227. * if (0xD800 &gt; prev || prev &gt; 0xDBFF) { // (could change last hex to 0xDB7F to treat high private
  228. * surrogates as single characters)
  229. * throw 'Low surrogate without preceding high surrogate';
  230. * }
  231. * return false; // We can pass over low surrogates now as the second component in a pair which we
  232. * have already processed
  233. * }
  234. *
  235. * While the second example may be more frequently useful for those wishing to support non-BMP
  236. * characters (since the above does not require the caller to know where any non-BMP character might
  237. * appear), in the event that one _does_ wish, in choosing a character by index, to treat the surrogate
  238. * pairs within a string as the single characters they represent, one can use the following:
  239. *
  240. * function fixedCharAt (str, idx) {
  241. * var ret = '';
  242. * str += '';
  243. * var end = str.length;
  244. *
  245. * var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  246. * while ((surrogatePairs.exec(str)) != null) {
  247. * var li = surrogatePairs.lastIndex;
  248. * if (li - 2 &lt; idx) {
  249. * idx++;
  250. * }
  251. * else {
  252. * break;
  253. * }
  254. * }
  255. *
  256. * if (idx &gt;= end || idx &lt; 0) {
  257. * return '';
  258. * }
  259. *
  260. * ret += str.charAt(idx);
  261. *
  262. * if (/[\uD800-\uDBFF]/.test(ret) &amp;&amp; /[\uDC00-\uDFFF]/.test(str.charAt(idx+1))) {
  263. * ret += str.charAt(idx+1); // Go one further, since one of the &quot;characters&quot; is part of a
  264. * surrogate pair
  265. * }
  266. * return ret;
  267. * }
  268. *
  269. * @param {Number} index An integer between 0 and 1 less than the length of the string.
  270. * @return {String} Individual character from string.
  271. */
  272. <span id='String-method-charCodeAt'>/**
  273. </span> * @method charCodeAt
  274. * Returns a number indicating the Unicode value of the character at the given index.
  275. *
  276. * Unicode code points range from 0 to 1,114,111. The first 128 Unicode code points are a direct match
  277. * of the ASCII character encoding.
  278. *
  279. * Note that `charCodeAt` will always return a value that is less than 65,536. This is because the
  280. * higher code points are represented by a pair of (lower valued) &quot;surrogate&quot; pseudo-characters which
  281. * are used to comprise the real character. Because of this, in order to examine or reproduce the full
  282. * character for individual characters of value 65,536 and above, for such characters, it is necessary
  283. * to retrieve not only `charCodeAt(i)`, but also `charCodeAt(i+1)` (as if examining/reproducing a
  284. * string with two letters). See example 2 and 3 below.
  285. *
  286. * `charCodeAt` returns `NaN` if the given index is not greater than 0 or is greater than the length of
  287. * the string.
  288. *
  289. * Backward Compatibility with JavaScript 1.2
  290. *
  291. * The `charCodeAt` method returns a number indicating the ISO-Latin-1 codeset value of the character
  292. * at the given index. The ISO-Latin-1 codeset ranges from 0 to 255. The first 0 to 127 are a direct
  293. * match of the ASCII character set.
  294. *
  295. * Example 1: Using `charCodeAt`
  296. *
  297. * The following example returns 65, the Unicode value for A.
  298. *
  299. * &quot;ABC&quot;.charCodeAt(0) // returns 65
  300. *
  301. * Example 2: Fixing `charCodeAt` to handle non-Basic-Multilingual-Plane characters if their presence
  302. * earlier in the string is unknown
  303. *
  304. * This version might be used in for loops and the like when it is unknown whether non-BMP characters
  305. * exist before the specified index position.
  306. *
  307. * function fixedCharCodeAt (str, idx) {
  308. * // ex. fixedCharCodeAt ('\uD800\uDC00', 0); // 65536
  309. * // ex. fixedCharCodeAt ('\uD800\uDC00', 1); // 65536
  310. * idx = idx || 0;
  311. * var code = str.charCodeAt(idx);
  312. * var hi, low;
  313. * if (0xD800 &lt;= code &amp;&amp; code &lt;= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
  314. * hi = code;
  315. * low = str.charCodeAt(idx+1);
  316. * if (isNaN(low)) {
  317. * throw 'High surrogate not followed by low surrogate in fixedCharCodeAt()';
  318. * }
  319. * return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
  320. * }
  321. * if (0xDC00 &lt;= code &amp;&amp; code &lt;= 0xDFFF) { // Low surrogate
  322. * // We return false to allow loops to skip this iteration since should have already handled
  323. * high surrogate above in the previous iteration
  324. * return false;
  325. * }
  326. * return code;
  327. * }
  328. *
  329. * Example 3: Fixing `charCodeAt` to handle non-Basic-Multilingual-Plane characters if their presence
  330. * earlier in the string is known
  331. *
  332. * function knownCharCodeAt (str, idx) {
  333. * str += '';
  334. * var code,
  335. * end = str.length;
  336. *
  337. * var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  338. * while ((surrogatePairs.exec(str)) != null) {
  339. * var li = surrogatePairs.lastIndex;
  340. * if (li - 2 &lt; idx) {
  341. * idx++;
  342. * }
  343. * else {
  344. * break;
  345. * }
  346. * }
  347. *
  348. * if (idx &gt;= end || idx &lt; 0) {
  349. * return NaN;
  350. * }
  351. *
  352. * code = str.charCodeAt(idx);
  353. *
  354. * var hi, low;
  355. * if (0xD800 &lt;= code &amp;&amp; code &lt;= 0xDBFF) {
  356. * hi = code;
  357. * low = str.charCodeAt(idx+1); // Go one further, since one of the &quot;characters&quot; is part of
  358. * a surrogate pair
  359. * return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
  360. * }
  361. * return code;
  362. * }
  363. *
  364. * @param {Number} index An integer greater than 0 and less than the length of the string; if it is
  365. * not a number, it defaults to 0.
  366. * @return {Number} Value between 0 and 65535.
  367. */
  368. <span id='String-method-concat'>/**
  369. </span> * @method concat
  370. * Combines the text of two strings and returns a new string.
  371. *
  372. * `concat` combines the text from one or more strings and returns a new string. Changes to the text in
  373. * one string do not affect the other string.
  374. *
  375. * The following example combines strings into a new string.
  376. *
  377. * var hello = &quot;Hello, &quot;;
  378. * console.log(hello.concat(&quot;Kevin&quot;, &quot; have a nice day.&quot;)); // Hello, Kevin have a nice day.
  379. *
  380. * @param {String} string2...stringN
  381. * @return {String} Result of both strings.
  382. */
  383. <span id='String-method-indexOf'>/**
  384. </span> * @method indexOf
  385. * Returns the index within the calling `String` object of the first occurrence of the specified value,
  386. * or -1 if not found.
  387. *
  388. * Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character
  389. * of a string called `stringName` is `stringName.length - 1`.
  390. *
  391. * &quot;Blue Whale&quot;.indexOf(&quot;Blue&quot;) // returns 0
  392. * &quot;Blue Whale&quot;.indexOf(&quot;Blute&quot;) // returns -1
  393. * &quot;Blue Whale&quot;.indexOf(&quot;Whale&quot;,0) // returns 5
  394. * &quot;Blue Whale&quot;.indexOf(&quot;Whale&quot;,5) // returns 5
  395. * &quot;Blue Whale&quot;.indexOf(&quot;&quot;,9) // returns 9
  396. * &quot;Blue Whale&quot;.indexOf(&quot;&quot;,10) // returns 10
  397. * &quot;Blue Whale&quot;.indexOf(&quot;&quot;,11) // returns 10
  398. *
  399. * The `indexOf` method is case sensitive. For example, the following expression returns -1:
  400. *
  401. * &quot;Blue Whale&quot;.indexOf(&quot;blue&quot;)
  402. *
  403. * Note that '0' doesn't evaluate to true and '-1' doesn't evaluate to false. Therefore, when checking if a specific string exists
  404. * within another string the correct way to check would be:
  405. *
  406. * &quot;Blue Whale&quot;.indexOf(&quot;Blue&quot;) != -1 // true
  407. * &quot;Blue Whale&quot;.indexOf(&quot;Bloe&quot;) != -1 // false
  408. *
  409. * The following example uses indexOf and lastIndexOf to locate values in the string &quot;Brave new world&quot;.
  410. *
  411. * var anyString=&quot;Brave new world&quot;
  412. *
  413. * document.write(&quot;&lt;P&gt;The index of the first w from the beginning is &quot; + anyString.indexOf(&quot;w&quot;)) // Displays 8
  414. * document.write(&quot;&lt;P&gt;The index of the first w from the end is &quot; + anyString.lastIndexOf(&quot;w&quot;)) // Displays 10
  415. * document.write(&quot;&lt;P&gt;The index of 'new' from the beginning is &quot; + anyString.indexOf(&quot;new&quot;)) // Displays 6
  416. * document.write(&quot;&lt;P&gt;The index of 'new' from the end is &quot; + anyString.lastIndexOf(&quot;new&quot;)) // Displays 6
  417. *
  418. * The following example defines two string variables. The variables contain the same string except that the second string contains
  419. * uppercase letters. The first `writeln` method displays 19. But because the `indexOf` method is case sensitive, the string
  420. * &quot;cheddar&quot; is not found in `myCapString`, so the second `writeln` method displays -1.
  421. *
  422. * myString=&quot;brie, pepper jack, cheddar&quot;
  423. * myCapString=&quot;Brie, Pepper Jack, Cheddar&quot;
  424. * document.writeln('myString.indexOf(&quot;cheddar&quot;) is ' + myString.indexOf(&quot;cheddar&quot;))
  425. * document.writeln('&lt;P&gt;myCapString.indexOf(&quot;cheddar&quot;) is ' + myCapString.indexOf(&quot;cheddar&quot;))
  426. *
  427. * The following example sets count to the number of occurrences of the letter x in the string str:
  428. *
  429. * count = 0;
  430. * pos = str.indexOf(&quot;x&quot;);
  431. * while ( pos != -1 ) {
  432. * count++;
  433. * pos = str.indexOf(&quot;x&quot;,pos+1);
  434. * }
  435. *
  436. * @param {String} searchValue A string representing the value to search for.
  437. * @param {Number} fromIndex The location within the calling string to start the search from. It can be any integer between 0 and
  438. * the length of the string. The default value is 0.
  439. * @return {Number} Position of specified value or -1 if not found.
  440. */
  441. <span id='String-method-lastIndexOf'>/**
  442. </span> * @method lastIndexOf
  443. * Returns the index within the calling String object of the last occurrence of
  444. * the specified value, or -1 if not found. The calling string is searched
  445. * backward, starting at fromIndex.
  446. *
  447. * Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character
  448. * is `stringName.length - 1`.
  449. *
  450. * &quot;canal&quot;.lastIndexOf(&quot;a&quot;) // returns 3
  451. * &quot;canal&quot;.lastIndexOf(&quot;a&quot;,2) // returns 1
  452. * &quot;canal&quot;.lastIndexOf(&quot;a&quot;,0) // returns -1
  453. * &quot;canal&quot;.lastIndexOf(&quot;x&quot;) // returns -1
  454. *
  455. * The `lastIndexOf` method is case sensitive. For example, the following expression returns -1:
  456. *
  457. * &quot;Blue Whale, Killer Whale&quot;.lastIndexOf(&quot;blue&quot;)
  458. *
  459. * The following example uses `indexOf` and `lastIndexOf` to locate values in the string &quot;`Brave new world`&quot;.
  460. *
  461. * var anyString=&quot;Brave new world&quot;
  462. *
  463. * // Displays 8
  464. * document.write(&quot;&lt;P&gt;The index of the first w from the beginning is &quot; +
  465. * anyString.indexOf(&quot;w&quot;))
  466. * // Displays 10
  467. * document.write(&quot;&lt;P&gt;The index of the first w from the end is &quot; +
  468. * anyString.lastIndexOf(&quot;w&quot;))
  469. * // Displays 6
  470. * document.write(&quot;&lt;P&gt;The index of 'new' from the beginning is &quot; +
  471. * anyString.indexOf(&quot;new&quot;))
  472. * // Displays 6
  473. * document.write(&quot;&lt;P&gt;The index of 'new' from the end is &quot; +
  474. * anyString.lastIndexOf(&quot;new&quot;))
  475. *
  476. * @param {String} searchValue A string representing the value to search for.
  477. * @param {Number} fromIndex The location within the calling string to start the search from, indexed from left to right. It can
  478. * be any integer between 0 and the length of the string. The default value is the length of the string.
  479. * @return {Number}
  480. */
  481. <span id='String-method-localeCompare'>/**
  482. </span> * @method localeCompare
  483. * Returns a number indicating whether a reference string comes before or after or is the same as the
  484. * given string in sort order.
  485. *
  486. * Returns a number indicating whether a reference string comes before or after or is the same as the
  487. * given string in sort order. Returns -1 if the string occurs earlier in a sort than `compareString`,
  488. * returns 1 if the string occurs afterwards in such a sort, and returns 0 if they occur at the same
  489. * level.
  490. *
  491. * The following example demonstrates the different potential results for a string occurring before,
  492. * after, or at the same level as another:
  493. *
  494. * alert('a'.localeCompare('b')); // -1
  495. * alert('b'.localeCompare('a')); // 1
  496. * alert('b'.localeCompare('b')); // 0
  497. *
  498. * @param {String} compareString The string against which the referring string is comparing.
  499. * @return {Number} Returns -1 if the string occurs earlier in a sort than
  500. * compareString, returns 1 if the string occurs afterwards in such a sort, and
  501. * returns 0 if they occur at the same level.
  502. */
  503. <span id='String-method-match'>/**
  504. </span> * @method match
  505. * Used to match a regular expression against a string.
  506. *
  507. * If the regular expression does not include the `g` flag, returns the same result as `regexp.exec(string)`.
  508. *
  509. * If the regular expression includes the `g` flag, the method returns an Array containing all matches. If there were no matches,
  510. * the method returns `null`.
  511. *
  512. * The returned {@link Array} has an extra `input` property, which contains the regexp that generated it as a result. In addition,
  513. * it has an `index` property, which represents the zero-based index of the match in the string.
  514. *
  515. * In the following example, `match` is used to find &quot;Chapter&quot; followed by 1 or more numeric characters followed by a decimal point
  516. * and numeric character 0 or more times. The regular expression includes the `i` flag so that case will be ignored.
  517. *
  518. * str = &quot;For more information, see Chapter 3.4.5.1&quot;;
  519. * re = /(chapter \d+(\.\d)*)/i;
  520. * found = str.match(re);
  521. * document.write(found);
  522. *
  523. * This returns the array containing Chapter 3.4.5.1,Chapter 3.4.5.1,.1
  524. *
  525. * &quot;`Chapter 3.4.5.1`&quot; is the first match and the first value remembered from `(Chapter \d+(\.\d)*)`.
  526. *
  527. * &quot;`.1`&quot; is the second value remembered from `(\.\d)`.
  528. *
  529. * The following example demonstrates the use of the global and ignore case flags with `match`. All letters A through E and a
  530. * through e are returned, each its own element in the array
  531. *
  532. * var str = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;;
  533. * var regexp = /[A-E]/gi;
  534. * var matches_array = str.match(regexp);
  535. * document.write(matches_array);
  536. *
  537. * `matches_array` now equals `['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']`.
  538. *
  539. * @param {RegExp} regexp A {@link RegExp} object. If a non-RegExp object `obj` is passed, it is
  540. * implicitly converted to a RegExp by using `new RegExp(obj)`.
  541. * @return {Array} Contains results of the match (if any).
  542. */
  543. <span id='String-method-replace'>/**
  544. </span> * @method replace
  545. * Used to find a match between a regular expression and a string, and to replace the matched substring
  546. * with a new substring.
  547. *
  548. * This method does not change the `String` object it is called on. It simply returns a new string.
  549. *
  550. * To perform a global search and replace, either include the `g` flag in the regular expression or if
  551. * the first parameter is a string, include `g` in the flags parameter.
  552. *
  553. * The replacement string can include the following special replacement patterns:
  554. *
  555. * | Pattern | Inserts
  556. * |:--------------|:--------------------------------------------------------------------------------------
  557. * | `$$` | Inserts a `$`.
  558. * | `$&amp;` | Inserts the matched substring.
  559. * | `$`` | Inserts the portion of the string that precedes the matched substring.
  560. * | `$'` | Inserts the portion of the string that follows the matched substring.
  561. * | `$n` or `$nn` | Where `n` or `nn` are decimal digits, inserts the _n_th parenthesized submatch string, provided the first
  562. * | | argument was a `RegExp` object.
  563. *
  564. * You can specify a function as the second parameter. In this case, the function will be invoked after the match has been
  565. * performed. The function's result (return value) will be used as the replacement string. (Note: the above-mentioned special
  566. * replacement patterns do not apply in this case.) Note that the function will be invoked multiple times for each full match to be
  567. * replaced if the regular expression in the first parameter is global.
  568. *
  569. * The arguments to the function are as follows:
  570. *
  571. * | Possible Name | Supplied Value
  572. * |:--------------|:--------------------------------------------------------------------------------------
  573. * | `str` | The matched substring. (Corresponds to `$&amp;` above.)
  574. * | `p1, p2, ...` | The _n_th parenthesized submatch string, provided the first argument to replace was a `RegExp` object.
  575. * | | (Correspond to $1, $2, etc. above.)
  576. * | `offset` | The offset of the matched substring within the total string being examined. (For example, if the total string
  577. * | | was &quot;`abcd`&quot;, and the matched substring was &quot;`bc`&quot;, then this argument will be 1.)
  578. * | `s` | The total string being examined.
  579. *
  580. * (The exact number of arguments will depend on whether the first argument was a `RegExp` object and, if so, how many parenthesized
  581. * submatches it specifies.)
  582. *
  583. * The following example will set `newString` to &quot;`XXzzzz - XX , zzzz`&quot;:
  584. *
  585. * function replacer(str, p1, p2, offset, s)
  586. * {
  587. * return str + &quot; - &quot; + p1 + &quot; , &quot; + p2;
  588. * }
  589. * var newString = &quot;XXzzzz&quot;.replace(/(X*)(z*)/, replacer);
  590. *
  591. * In the following example, the regular expression includes the global and ignore case flags which permits replace to replace each
  592. * occurrence of 'apples' in the string with 'oranges'.
  593. *
  594. * var re = /apples/gi;
  595. * var str = &quot;Apples are round, and apples are juicy.&quot;;
  596. * var newstr = str.replace(re, &quot;oranges&quot;);
  597. * print(newstr);
  598. *
  599. * In this version, a string is used as the first parameter and the global and ignore case flags are specified in the flags
  600. * parameter.
  601. *
  602. * var str = &quot;Apples are round, and apples are juicy.&quot;;
  603. * var newstr = str.replace(&quot;apples&quot;, &quot;oranges&quot;, &quot;gi&quot;);
  604. * print(newstr);
  605. *
  606. * Both of these examples print &quot;oranges are round, and oranges are juicy.&quot;
  607. *
  608. * In the following example, the regular expression is defined in replace and includes the ignore case flag.
  609. *
  610. * var str = &quot;Twas the night before Xmas...&quot;;
  611. * var newstr = str.replace(/xmas/i, &quot;Christmas&quot;);
  612. * print(newstr);
  613. *
  614. * This prints &quot;Twas the night before Christmas...&quot;
  615. *
  616. * The following script switches the words in the string. For the replacement text, the script uses the $1 and $2 replacement
  617. * patterns.
  618. *
  619. * var re = /(\w+)\s(\w+)/;
  620. * var str = &quot;John Smith&quot;;
  621. * var newstr = str.replace(re, &quot;$2, $1&quot;);
  622. * print(newstr);
  623. *
  624. * This prints &quot;Smith, John&quot;.
  625. *
  626. * In this example, all occurrences of capital letters in the string are converted to lower case, and a hyphen is inserted just
  627. * before the match location. The important thing here is that additional operations are needed on the matched item before it is
  628. * given back as a replacement.
  629. *
  630. * The replacement function accepts the matched snippet as its parameter, and uses it to transform the case and concatenate the
  631. * hyphen before returning.
  632. *
  633. * function styleHyphenFormat(propertyName)
  634. * {
  635. * function upperToHyphenLower(match)
  636. * {
  637. * return '-' + match.toLowerCase();
  638. * }
  639. * return propertyName.replace(/[A-Z]/, upperToHyphenLower);
  640. * }
  641. *
  642. * Given `styleHyphenFormat('borderTop')`, this returns 'border-top'.
  643. *
  644. * Because we want to further transform the _result_ of the match before the final substitution is made, we must use a function.
  645. * This forces the evaluation of the match prior to the `toLowerCase()` method. If we had tried to do this using the match without a
  646. * function, the `toLowerCase()` would have no effect.
  647. *
  648. * var newString = propertyName.replace(/[A-Z]/, '-' + '$&amp;'.toLowerCase()); // won't work
  649. *
  650. * This is because `'$&amp;'.toLowerCase()` would be evaluated first as a string literal (resulting in the same `'$&amp;'`) before using the
  651. * characters as a pattern.
  652. *
  653. * The following example replaces a Fahrenheit degree with its equivalent Celsius degree. The Fahrenheit degree should be a number
  654. * ending with F. The function returns the Celsius number ending with C. For example, if the input number is 212F, the function
  655. * returns 100C. If the number is 0F, the function returns -17.77777777777778C.
  656. *
  657. * The regular expression `test` checks for any number that ends with F. The number of Fahrenheit degree is accessible to the
  658. * function through its second parameter, `p1`. The function sets the Celsius number based on the Fahrenheit degree passed in a
  659. * string to the `f2c` function. `f2c` then returns the Celsius number. This function approximates Perl's `s///e` flag.
  660. *
  661. * function f2c(x)
  662. * {
  663. * function convert(str, p1, offset, s)
  664. * {
  665. * return ((p1-32) * 5/9) + &quot;C&quot;;
  666. * }
  667. * var s = String(x);
  668. * var test = /(\d+(?:\.\d*)?)F\b/g;
  669. * return s.replace(test, convert);
  670. * }
  671. *
  672. * @param {String/RegExp} pattern Either a string or regular expression pattern to search for.
  673. *
  674. * @param {String/Function} replacement Either string or function:
  675. *
  676. * - The String to replace the `pattern` with. Number of special replacement patterns are supported;
  677. * see the &quot;Specifying a string as a parameter&quot; section above.
  678. * - A function to be invoked to create the replacement.
  679. * The arguments supplied to this function are described in the &quot;Specifying a function as a parameter&quot;
  680. * section above.
  681. *
  682. * @return {String} String of matched replaced items.
  683. */
  684. <span id='String-method-search'>/**
  685. </span> * @method search
  686. * Executes the search for a match between a regular expression and a specified string.
  687. *
  688. * If successful, search returns the index of the regular expression inside the string. Otherwise, it
  689. * returns -1.
  690. *
  691. * When you want to know whether a pattern is found in a string use search (similar to the regular
  692. * expression `test` method); for more information (but slower execution) use `match` (similar to the
  693. * regular expression `exec` method).
  694. *
  695. * The following example prints a message which depends on the success of the test.
  696. *
  697. * function testinput(re, str){
  698. * if (str.search(re) != -1)
  699. * midstring = &quot; contains &quot;;
  700. * else
  701. * midstring = &quot; does not contain &quot;;
  702. * document.write (str + midstring + re);
  703. * }
  704. *
  705. * @param {RegExp} regexp A regular expression object. If a non-RegExp object obj is passed, it is
  706. * implicitly converted to a RegExp by using `new RegExp(obj)`.
  707. * @return {Number} If successful, search returns the index of the regular
  708. * expression inside the string. Otherwise, it returns -1.
  709. */
  710. <span id='String-method-slice'>/**
  711. </span> * @method slice
  712. * Extracts a section of a string and returns a new string.
  713. *
  714. * `slice` extracts the text from one string and returns a new string. Changes to the text in one
  715. * string do not affect the other string.
  716. *
  717. * `slice` extracts up to but not including `endSlice`. `string.slice(1,4)` extracts the second
  718. * character through the fourth character (characters indexed 1, 2, and 3).
  719. *
  720. * As a negative index, `endSlice` indicates an offset from the end of the string. `string.slice(2,-1)`
  721. * extracts the third character through the second to last character in the string.
  722. *
  723. * The following example uses slice to create a new string.
  724. *
  725. * // assumes a print function is defined
  726. * var str1 = &quot;The morning is upon us.&quot;;
  727. * var str2 = str1.slice(4, -2);
  728. * print(str2);
  729. *
  730. * This writes:
  731. *
  732. * morning is upon u
  733. *
  734. * @param {Number} beginSlice The zero-based index at which to begin extraction.
  735. * @param {Number} endSlice The zero-based index at which to end extraction. If omitted, `slice`
  736. * extracts to the end of the string.
  737. * @return {String} All characters from specified start up to (but excluding)
  738. * end.
  739. */
  740. <span id='String-method-split'>/**
  741. </span> * @method split
  742. * Splits a `String` object into an array of strings by separating the string into substrings.
  743. *
  744. * The `split` method returns the new array.
  745. *
  746. * When found, `separator` is removed from the string and the substrings are returned in an array. If
  747. * `separator` is omitted, the array contains one element consisting of the entire string.
  748. *
  749. * If `separator` is a regular expression that contains capturing parentheses, then each time separator
  750. * is matched the results (including any undefined results) of the capturing parentheses are spliced
  751. * into the output array. However, not all browsers support this capability.
  752. *
  753. * Note: When the string is empty, `split` returns an array containing one empty string, rather than an
  754. * empty array.
  755. *
  756. * The following example defines a function that splits a string into an array of strings using the
  757. * specified separator. After splitting the string, the function displays messages indicating the
  758. * original string (before the split), the separator used, the number of elements in the array, and the
  759. * individual array elements.
  760. *
  761. * function splitString(stringToSplit,separator)
  762. * {
  763. * var arrayOfStrings = stringToSplit.split(separator);
  764. * print('The original string is: &quot;' + stringToSplit + '&quot;');
  765. * print('The separator is: &quot;' + separator + '&quot;');
  766. * print(&quot;The array has &quot; + arrayOfStrings.length + &quot; elements: &quot;);
  767. *
  768. * for (var i=0; i &lt; arrayOfStrings.length; i++)
  769. * print(arrayOfStrings[i] + &quot; / &quot;);
  770. * }
  771. *
  772. * var tempestString = &quot;Oh brave new world that has such people in it.&quot;;
  773. * var monthString = &quot;Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec&quot;;
  774. *
  775. * var space = &quot; &quot;;
  776. * var comma = &quot;,&quot;;
  777. *
  778. * splitString(tempestString, space);
  779. * splitString(tempestString);
  780. * splitString(monthString, comma);
  781. *
  782. * This example produces the following output:
  783. *
  784. * The original string is: &quot;Oh brave new world that has such people in it.&quot;
  785. * The separator is: &quot; &quot;
  786. * The array has 10 elements: Oh / brave / new / world / that / has / such / people / in / it. /
  787. *
  788. * The original string is: &quot;Oh brave new world that has such people in it.&quot;
  789. * The separator is: &quot;undefined&quot;
  790. * The array has 1 elements: Oh brave new world that has such people in it. /
  791. *
  792. * The original string is: &quot;Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec&quot;
  793. * The separator is: &quot;,&quot;
  794. * The array has 12 elements: Jan / Feb / Mar / Apr / May / Jun / Jul / Aug / Sep / Oct / Nov / Dec /
  795. *
  796. * In the following example, `split` looks for 0 or more spaces followed by a semicolon followed by 0
  797. * or more spaces and, when found, removes the spaces from the string. nameList is the array returned
  798. * as a result of split.
  799. *
  800. * var names = &quot;Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand &quot;;
  801. * print(names);
  802. * var re = /\s*;\s*\/;
  803. * var nameList = names.split(re);
  804. * print(nameList);
  805. *
  806. * This prints two lines; the first line prints the original string, and the second line prints the
  807. * resulting array.
  808. *
  809. * Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
  810. * Harry Trump,Fred Barney,Helen Rigby,Bill Abel,Chris Hand
  811. *
  812. * In the following example, split looks for 0 or more spaces in a string and returns the first 3
  813. * splits that it finds.
  814. *
  815. * var myString = &quot;Hello World. How are you doing?&quot;;
  816. * var splits = myString.split(&quot; &quot;, 3);
  817. * print(splits);
  818. *
  819. * This script displays the following:
  820. *
  821. * Hello,World.,How
  822. *
  823. * If `separator` contains capturing parentheses, matched results are returned in the array.
  824. *
  825. * var myString = &quot;Hello 1 word. Sentence number 2.&quot;;
  826. * var splits = myString.split(/(\d)/);
  827. * print(splits);
  828. *
  829. * This script displays the following:
  830. *
  831. * Hello ,1, word. Sentence number ,2, .
  832. *
  833. * @param {String} seperator Specifies the character to use for separating the string. The separator is treated as a string or a
  834. * regular expression. If separator is omitted, the array returned contains one element consisting of the entire string.
  835. * @param {Number} limit Integer specifying a limit on the number of splits to be found. The split method still splits on every
  836. * match of separator, but it truncates the returned array to at most limit elements.
  837. * @return {Array} Substrings are returned in an array.
  838. */
  839. <span id='String-method-substr'>/**
  840. </span> * @method substr
  841. * Returns the characters in a string beginning at the specified location through the specified number
  842. * of characters.
  843. *
  844. * `start` is a character index. The index of the first character is 0, and the index of the last
  845. * character is 1 less than the length of the string. `substr` begins extracting characters at start
  846. * and collects length characters (unless it reaches the end of the string first, in which case it will
  847. * return fewer).
  848. *
  849. * If `start` is positive and is greater than or equal to the length of the string, `substr` returns an
  850. * empty string.
  851. *
  852. * If `start` is negative, `substr` uses it as a character index from the end of the string. If start
  853. * is negative and abs(start) is larger than the length of the string, `substr` uses 0 as the start
  854. * index. Note: the described handling of negative values of the start argument is not supported by
  855. * Microsoft JScript.
  856. *
  857. * If length is 0 or negative, `substr` returns an empty string. If length is omitted, `substr`
  858. * extracts characters to the end of the string.
  859. *
  860. * Consider the following script:
  861. *
  862. * // assumes a print function is defined
  863. * var str = &quot;abcdefghij&quot;;
  864. * print(&quot;(1,2): &quot; + str.substr(1,2));
  865. * print(&quot;(-3,2): &quot; + str.substr(-3,2));
  866. * print(&quot;(-3): &quot; + str.substr(-3));
  867. * print(&quot;(1): &quot; + str.substr(1));
  868. * print(&quot;(-20, 2): &quot; + str.substr(-20,2));
  869. * print(&quot;(20, 2): &quot; + str.substr(20,2));
  870. *
  871. * This script displays:
  872. *
  873. * (1,2): bc
  874. * (-3,2): hi
  875. * (-3): hij
  876. * (1): bcdefghij
  877. * (-20, 2): ab
  878. * (20, 2):
  879. *
  880. * @param {Number} start Location at which to begin extracting characters.
  881. * @param {Number} length The number of characters to extract.
  882. * @return {String} Modified string.
  883. */
  884. <span id='String-method-substring'>/**
  885. </span> * @method substring
  886. * Returns the characters in a string between two indexes into the string.
  887. *
  888. * substring extracts characters from indexA up to but not including indexB. In particular:
  889. * * If `indexA` equals `indexB`, `substring` returns an empty string.
  890. * * If `indexB` is omitted, substring extracts characters to the end of the string.
  891. * * If either argument is less than 0 or is `NaN`, it is treated as if it were 0.
  892. * * If either argument is greater than `stringName.length`, it is treated as if it were
  893. * `stringName.length`.
  894. *
  895. * If `indexA` is larger than `indexB`, then the effect of substring is as if the two arguments were
  896. * swapped; for example, `str.substring(1, 0) == str.substring(0, 1)`.
  897. *
  898. * The following example uses substring to display characters from the string &quot;Sencha&quot;:
  899. *
  900. * // assumes a print function is defined
  901. * var anyString = &quot;Sencha&quot;;
  902. *
  903. * // Displays &quot;Sen&quot;
  904. * print(anyString.substring(0,3));
  905. * print(anyString.substring(3,0));
  906. *
  907. * // Displays &quot;cha&quot;
  908. * print(anyString.substring(3,6));
  909. * print(anyString.substring(6,3));
  910. *
  911. * // Displays &quot;Sencha&quot;
  912. * print(anyString.substring(0,6));
  913. * print(anyString.substring(0,10));
  914. *
  915. * The following example replaces a substring within a string. It will replace both individual
  916. * characters and `substrings`. The function call at the end of the example changes the string &quot;Brave
  917. * New World&quot; into &quot;Brave New Web&quot;.
  918. *
  919. * function replaceString(oldS, newS, fullS) {
  920. * // Replaces oldS with newS in the string fullS
  921. * for (var i = 0; i &lt; fullS.length; i++) {
  922. * if (fullS.substring(i, i + oldS.length) == oldS) {
  923. * fullS = fullS.substring(0, i) + newS + fullS.substring(i + oldS.length,
  924. * fullS.length);
  925. * }
  926. * }
  927. * return fullS;
  928. * }
  929. *
  930. * replaceString(&quot;World&quot;, &quot;Web&quot;, &quot;Brave New World&quot;);
  931. *
  932. * @param {Number} indexA An integer between 0 and one less than the length of the string.
  933. * @param {Number} indexB (optional) An integer between 0 and the length of the string.
  934. * @return {String} Returns the characters in a string between two indexes into the string.
  935. */
  936. <span id='String-method-toLocaleLowerCase'>/**
  937. </span> * @method toLocaleLowerCase
  938. * The characters within a string are converted to lower case while respecting the current locale. For
  939. * most languages, this will return the same as `toLowerCase`.
  940. *
  941. * The `toLocaleLowerCase` method returns the value of the string converted to lower case according to
  942. * any locale-specific case mappings. `toLocaleLowerCase` does not affect the value of the string
  943. * itself. In most cases, this will produce the same result as `toLowerCase()`, but for some locales,
  944. * such as Turkish, whose case mappings do not follow the default case mappings in Unicode, there may
  945. * be a different result.
  946. *
  947. * The following example displays the string &quot;sencha&quot;:
  948. *
  949. * var upperText=&quot;sencha&quot;;
  950. * document.write(upperText.toLocaleLowerCase());
  951. *
  952. * @return {String} Returns value of the string in lowercase.
  953. */
  954. <span id='String-method-toLocaleUpperCase'>/**
  955. </span> * @method toLocaleUpperCase
  956. * The characters within a string are converted to upper case while respecting the current locale. For
  957. * most languages, this will return the same as `toUpperCase`.
  958. *
  959. * The `toLocaleUpperCase` method returns the value of the string converted to upper case according to
  960. * any locale-specific case mappings. `toLocaleUpperCase` does not affect the value of the string
  961. * itself. In most cases, this will produce the same result as `toUpperCase()`, but for some locales,
  962. * such as Turkish, whose case mappings do not follow the default case mappings in Unicode, there may
  963. * be a different result.
  964. *
  965. * The following example displays the string &quot;SENCHA&quot;:
  966. *
  967. * var lowerText=&quot;sencha&quot;;
  968. * document.write(lowerText.toLocaleUpperCase());
  969. *
  970. * @return {String} Returns value of the string in uppercase.
  971. */
  972. <span id='String-method-toLowerCase'>/**
  973. </span> * @method toLowerCase
  974. * Returns the calling string value converted to lower case.
  975. *
  976. * The `toLowerCase` method returns the value of the string converted to lowercase. `toLowerCase` does
  977. * not affect the value of the string itself.
  978. *
  979. * The following example displays the lowercase string &quot;sencha&quot;:
  980. *
  981. * var upperText=&quot;SENCHA&quot;;
  982. * document.write(upperText.toLowerCase());
  983. *
  984. * @return {String} Returns value of the string in lowercase.
  985. */
  986. <span id='String-method-toString'>/**
  987. </span> * @method toString
  988. * Returns a string representing the specified object. Overrides the `Object.toString` method.
  989. *
  990. * The `String` object overrides the `toString` method of the `Object` object; it does not inherit
  991. * `Object.toString`. For `String` objects, the `toString` method returns a string representation of
  992. * the object.
  993. *
  994. * The following example displays the string value of a String object:
  995. *
  996. * x = new String(&quot;Hello world&quot;);
  997. * alert(x.toString()) // Displays &quot;Hello world&quot;
  998. *
  999. * @return {String} A string representation of the object.
  1000. */
  1001. <span id='String-method-toUpperCase'>/**
  1002. </span> * @method toUpperCase
  1003. * Returns the calling string value converted to uppercase.
  1004. *
  1005. * The `toUpperCase` method returns the value of the string converted to uppercase. `toUpperCase` does
  1006. * not affect the value of the string itself.
  1007. *
  1008. * The following example displays the string &quot;SENCHA&quot;:
  1009. * var lowerText=&quot;sencha&quot;;
  1010. * document.write(lowerText.toUpperCase());
  1011. *
  1012. * @return {String} Returns value of the string in uppercase.
  1013. */
  1014. <span id='String-method-valueOf'>/**
  1015. </span> * @method valueOf
  1016. * Returns the primitive value of the specified object. Overrides the `Object.valueOf` method.
  1017. *
  1018. * The `valueOf` method of String returns the primitive value of a `String` object as a string data
  1019. * type. This value is equivalent to `String.toString`.
  1020. *
  1021. * This method is usually called internally by JavaScript and not explicitly in code.
  1022. *
  1023. * x = new String(&quot;Hello world&quot;);
  1024. * alert(x.valueOf()) // Displays &quot;Hello world&quot;
  1025. *
  1026. * @return {String} Returns value of string.
  1027. */</pre>
  1028. </body>
  1029. </html>