-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathJs.String.html
908 lines (718 loc) · 58.4 KB
/
Js.String.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="../api_static/tomorrow-night.css">
<link rel="stylesheet" href="../api_static/style.css" type="text/css">
<script src="../api_static//highlight.pack.js"></script>
<script src="../api_static//script.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<meta charset="utf8">
<link rel="previous" href="Js.Array2.html"><link rel="next" href="Js.String2.html">
<title> Js.String </title></head>
<body>
<nav class="module-index"><ul><li><a href="Belt.html">Belt</a></li>
<li><a href="Belt_Array.html">Belt_Array</a></li>
<li><a href="Belt_Float.html">Belt_Float</a></li>
<li><a href="Belt_HashMap.html">Belt_HashMap</a></li>
<li><a href="Belt_HashMapInt.html">Belt_HashMapInt</a></li>
<li><a href="Belt_HashMapString.html">Belt_HashMapString</a></li>
<li><a href="Belt_HashSet.html">Belt_HashSet</a></li>
<li><a href="Belt_HashSetInt.html">Belt_HashSetInt</a></li>
<li><a href="Belt_HashSetString.html">Belt_HashSetString</a></li>
<li><a href="Belt_Id.html">Belt_Id</a></li>
<li><a href="Belt_Int.html">Belt_Int</a></li>
<li><a href="Belt_List.html">Belt_List</a></li>
<li><a href="Belt_Map.html">Belt_Map</a></li>
<li><a href="Belt_MapDict.html">Belt_MapDict</a></li>
<li><a href="Belt_MapInt.html">Belt_MapInt</a></li>
<li><a href="Belt_MapString.html">Belt_MapString</a></li>
<li><a href="Belt_MutableMap.html">Belt_MutableMap</a></li>
<li><a href="Belt_MutableMapInt.html">Belt_MutableMapInt</a></li>
<li><a href="Belt_MutableMapString.html">Belt_MutableMapString</a></li>
<li><a href="Belt_MutableQueue.html">Belt_MutableQueue</a></li>
<li><a href="Belt_MutableSet.html">Belt_MutableSet</a></li>
<li><a href="Belt_MutableSetInt.html">Belt_MutableSetInt</a></li>
<li><a href="Belt_MutableSetString.html">Belt_MutableSetString</a></li>
<li><a href="Belt_MutableStack.html">Belt_MutableStack</a></li>
<li><a href="Belt_Option.html">Belt_Option</a></li>
<li><a href="Belt_Range.html">Belt_Range</a></li>
<li><a href="Belt_Result.html">Belt_Result</a></li>
<li><a href="Belt_Set.html">Belt_Set</a></li>
<li><a href="Belt_SetDict.html">Belt_SetDict</a></li>
<li><a href="Belt_SetInt.html">Belt_SetInt</a></li>
<li><a href="Belt_SetString.html">Belt_SetString</a></li>
<li><a href="Belt_SortArray.html">Belt_SortArray</a></li>
<li><a href="Belt_SortArrayInt.html">Belt_SortArrayInt</a></li>
<li><a href="Belt_SortArrayString.html">Belt_SortArrayString</a></li>
<li><a href="Belt_internalAVLset.html">Belt_internalAVLset</a></li>
<li><a href="Belt_internalAVLtree.html">Belt_internalAVLtree</a></li>
<li><a href="Belt_internalBuckets.html">Belt_internalBuckets</a></li>
<li><a href="Belt_internalBucketsType.html">Belt_internalBucketsType</a></li>
<li><a href="Belt_internalMapInt.html">Belt_internalMapInt</a></li>
<li><a href="Belt_internalMapString.html">Belt_internalMapString</a></li>
<li><a href="Belt_internalSetBuckets.html">Belt_internalSetBuckets</a></li>
<li><a href="Belt_internalSetInt.html">Belt_internalSetInt</a></li>
<li><a href="Belt_internalSetString.html">Belt_internalSetString</a></li>
<li><a href="Dom.html">Dom</a></li>
<li><a href="Dom_storage.html">Dom_storage</a></li>
<li><a href="Dom_storage2.html">Dom_storage2</a></li>
<li><a href="Js.html">Js</a></li>
<li><a href="Js_OO.html">Js_OO</a></li>
<li><a href="Js_array.html">Js_array</a></li>
<li><a href="Js_array2.html">Js_array2</a></li>
<li><a href="Js_cast.html">Js_cast</a></li>
<li><a href="Js_console.html">Js_console</a></li>
<li><a href="Js_date.html">Js_date</a></li>
<li><a href="Js_dict.html">Js_dict</a></li>
<li><a href="Js_exn.html">Js_exn</a></li>
<li><a href="Js_float.html">Js_float</a></li>
<li><a href="Js_global.html">Js_global</a></li>
<li><a href="Js_int.html">Js_int</a></li>
<li><a href="Js_json.html">Js_json</a></li>
<li><a href="Js_list.html">Js_list</a></li>
<li><a href="Js_mapperRt.html">Js_mapperRt</a></li>
<li><a href="Js_math.html">Js_math</a></li>
<li><a href="Js_null.html">Js_null</a></li>
<li><a href="Js_null_undefined.html">Js_null_undefined</a></li>
<li><a href="Js_obj.html">Js_obj</a></li>
<li><a href="Js_option.html">Js_option</a></li>
<li><a href="Js_promise.html">Js_promise</a></li>
<li><a href="Js_re.html">Js_re</a></li>
<li><a href="Js_result.html">Js_result</a></li>
<li><a href="Js_string.html">Js_string</a></li>
<li><a href="Js_string2.html">Js_string2</a></li>
<li><a href="Js_typed_array.html">Js_typed_array</a></li>
<li><a href="Js_typed_array2.html">Js_typed_array2</a></li>
<li><a href="Js_types.html">Js_types</a></li>
<li><a href="Js_undefined.html">Js_undefined</a></li>
<li><a href="Js_vector.html">Js_vector</a></li>
<li><a href="Node.html">Node</a></li>
<li><a href="Node_buffer.html">Node_buffer</a></li>
<li><a href="Node_child_process.html">Node_child_process</a></li>
<li><a href="Node_fs.html">Node_fs</a></li>
<li><a href="Node_module.html">Node_module</a></li>
<li><a href="Node_path.html">Node_path</a></li>
<li><a href="Node_process.html">Node_process</a></li></ul></nav>
<div class="navbar"><a class="pre" href="Js.Array2.html" title="Js.Array2">Previous</a>
<a class="up" href="Js.html" title="Js">Up</a>
<a class="post" href="Js.String2.html" title="Js.String2">Next</a>
</div>
<h1>Module <a href="type_Js.String.html">Js.String</a></h1>
<pre><span id="MODULEString"><span class="keyword">module</span> String</span>: <code class="type"><a href="Js_string.html">Js_string</a></code></pre><hr width="100%">
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type"></code>t</span> = <code class="type">string</code> </pre>
<pre><span id="VALmake"><span class="keyword">val</span> make</span> : <code class="type">'a -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">make value</code> converts the given value to a string<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> make 3.5 = "3.5";;
make [|1;2;3|]) = "1,2,3";;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALfromCharCode"><span class="keyword">val</span> fromCharCode</span> : <code class="type">int -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">fromCharCode n</code>
creates a string containing the character corresponding to that number; <i>n</i> ranges from 0 to 65535. If out of range, the lower 16 bits of the value are used. Thus, <code class="code">fromCharCode 0x1F63A</code> gives the same result as <code class="code">fromCharCode 0xF63A</code>.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> fromCharCode 65 = "A";;
fromCharCode 0x3c8 = {js|ψ|js};;
fromCharCode 0xd55c = {js|한|js};;
fromCharCode -64568 = {js|ψ|js};;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALfromCharCodeMany"><span class="keyword">val</span> fromCharCodeMany</span> : <code class="type">int array -> <a href="Js_string.html#TYPEt">t</a></code></pre><p><code class="code">fromCharCodeMany [|n1;n2;n3|]</code> creates a string from the characters corresponding to the given numbers, using the same rules as <code class="code">fromCharCode</code>.</p>
<pre><span id="VALfromCodePoint"><span class="keyword">val</span> fromCodePoint</span> : <code class="type">int -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">fromCodePoint n</code>
creates a string containing the character corresponding to that numeric code point. If the number is not a valid code point, <b>raises</b> <code class="code">RangeError</code>. Thus, <code class="code">fromCodePoint 0x1F63A</code> will produce a correct value, unlike <code class="code">fromCharCode 0x1F63A</code>, and <code class="code">fromCodePoint -5</code> will raise a <code class="code">RangeError</code>.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> fromCodePoint 65 = "A";;
fromCodePoint 0x3c8 = {js|ψ|js};;
fromCodePoint 0xd55c = {js|한|js};;
fromCodePoint 0x1f63a = {js|😺|js};;
</code></pre> </pre>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALfromCodePointMany"><span class="keyword">val</span> fromCodePointMany</span> : <code class="type">int array -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">fromCharCodeMany [|n1;n2;n3|]</code> creates a string from the characters corresponding to the given code point numbers, using the same rules as <code class="code">fromCodePoint</code>.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> fromCodePointMany([|0xd55c; 0xae00; 0x1f63a|]) = {js|한글😺|js}
</code></pre> </pre>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALlength"><span class="keyword">val</span> length</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<div class="not-examples">
<code class="code">length s</code> returns the length of the given string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> length "abcd" = 4;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALget"><span class="keyword">val</span> get</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">get s n</code> returns as a string the character at the given index number. If <code class="code">n</code> is out of range, this function returns <code class="code">undefined</code>, so at some point this function may be modified to return <code class="code">t option</code>.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> get "Reason" 0 = "R";;
get "Reason" 4 = "o";;
get {js|Rẽasöń|js} 5 = {js|ń|js};;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALcharAt"><span class="keyword">val</span> charAt</span> : <code class="type">int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">charAt n s</code> gets the character at index <code class="code">n</code> within string <code class="code">s</code>. If <code class="code">n</code> is negative or greater than the length of <code class="code">s</code>, returns the empty string. If the string contains characters outside the range <code class="code">\u0000-\uffff</code>, it will return the first 16-bit value at that position in the string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> charAt 0, "Reason" = "R"
charAt( 12, "Reason") = "";
charAt( 5, {js|Rẽasöń|js} = {js|ń|js}
</code></pre> </pre>
</div>
</div>
<pre><span id="VALcharCodeAt"><span class="keyword">val</span> charCodeAt</span> : <code class="type">int -> <a href="Js_string.html#TYPEt">t</a> -> float</code></pre><div class="info ">
<div class="not-examples">
<code class="code">charCodeAt n s</code> returns the character code at position <code class="code">n</code> in string <code class="code">s</code>; the result is in the range 0-65535, unlke <code class="code">codePointAt</code>, so it will not work correctly for characters with code points greater than or equal to <code class="code">0x10000</code>.
The return type is <code class="code">float</code> because this function returns <code class="code">NaN</code> if <code class="code">n</code> is less than zero or greater than the length of the string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> charCodeAt 0 {js|😺|js} returns 0xd83d
codePointAt 0 {js|😺|js} returns Some 0x1f63a
</code></pre> </pre>
</div>
</div>
<pre><span id="VALcodePointAt"><span class="keyword">val</span> codePointAt</span> : <code class="type">int -> <a href="Js_string.html#TYPEt">t</a> -> int option</code></pre><div class="info ">
<div class="not-examples">
<code class="code">codePointAt n s</code> returns the code point at position <code class="code">n</code> within string <code class="code">s</code> as a <code class="code">Some</code> value. The return value handles code points greater than or equal to <code class="code">0x10000</code>. If there is no code point at the given position, the function returns <code class="code">None</code>.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> codePointAt 1 {js|¿😺?|js} = Some 0x1f63a
codePointAt 5 "abc" = None
</code></pre> </pre>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALconcat"><span class="keyword">val</span> concat</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">concat append original</code> returns a new string with <code class="code">append</code> added after <code class="code">original</code>.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> concat "bell" "cow" = "cowbell";;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALconcatMany"><span class="keyword">val</span> concatMany</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> array -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">concat arr original</code> returns a new string consisting of each item of an array of strings added to the <code class="code">original</code> string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> concatMany [|"2nd"; "3rd"; "4th"|] "1st" = "1st2nd3rd4th";;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALendsWith"><span class="keyword">val</span> endsWith</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> bool</code></pre><div class="info ">
<div class="not-examples">
ES2015:
<code class="code">endsWith substr str</code> returns <code class="code">true</code> if the <code class="code">str</code> ends with <code class="code">substr</code>, <code class="code">false</code> otherwise.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> endsWith "Script" "BuckleScript" = true;;
endsWith "Script" "BuckleShoes" = false;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALendsWithFrom"><span class="keyword">val</span> endsWithFrom</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> bool</code></pre><div class="info ">
<div class="not-examples">
<code class="code">endsWithFrom ending len str</code> returns <code class="code">true</code> if the first <code class="code">len</code> characters of <code class="code">str</code> end with <code class="code">ending</code>, <code class="code">false</code> otherwise. If <code class="code">n</code> is greater than or equal to the length of <code class="code">str</code>, then it works like <code class="code">endsWith</code>. (Honestly, this should have been named <code class="code">endsWithAt</code>, but oh well.)<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> endsWithFrom "cd" 4 "abcd" = true;;
endsWithFrom "cd" 3 "abcde" = false;;
endsWithFrom "cde" 99 "abcde" = true;;
endsWithFrom "ple" 7 "example.dat" = true;;
</code></pre> </pre>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALincludes"><span class="keyword">val</span> includes</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> bool</code></pre><div class="info ">
<div class="not-examples">
<code class="code">includes searchValue s</code> returns <code class="code">true</code> if <code class="code">searchValue</code> is found anywhere within <code class="code">s</code>, <code class="code">false</code> otherwise.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> includes "gram" "programmer" = true;;
includes "er" "programmer" = true;;
includes "pro" "programmer" = true;;
includes "xyz" "programmer" = false;;
</code></pre> </pre>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALincludesFrom"><span class="keyword">val</span> includesFrom</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> bool</code></pre><div class="info ">
<div class="not-examples">
<code class="code">includes searchValue start s</code> returns <code class="code">true</code> if <code class="code">searchValue</code> is found anywhere within <code class="code">s</code> starting at character number <code class="code">start</code> (where 0 is the first character), <code class="code">false</code> otherwise.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> includesFrom "gram" 1 "programmer" = true;;
includesFrom "gram" 4 "programmer" = false;;
includesFrom {js|한|js} 1 {js|대한민국|js} = true;;
</code></pre> </pre>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALindexOf"><span class="keyword">val</span> indexOf</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<div class="not-examples">
<code class="code">indexOf searchValue s</code> returns the position at which <code class="code">searchValue</code> was first found within <code class="code">s</code>, or <code class="code">-1</code> if <code class="code">searchValue</code> is not in <code class="code">s</code>.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> indexOf "ok" "bookseller" = 2;;
indexOf "sell" "bookseller" = 4;;
indexOf "ee" "beekeeper" = 1;;
indexOf "xyz" "bookseller" = -1;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALindexOfFrom"><span class="keyword">val</span> indexOfFrom</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<div class="not-examples">
<code class="code">indexOfFrom searchValue start s</code> returns the position at which <code class="code">searchValue</code> was found within <code class="code">s</code> starting at character position <code class="code">start</code>, or <code class="code">-1</code> if <code class="code">searchValue</code> is not found in that portion of <code class="code">s</code>. The return value is relative to the beginning of the string, no matter where the search started from.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> indexOfFrom "ok" 1 "bookseller" = 2;;
indexOfFrom "sell" 2 "bookseller" = 4;;
indexOfFrom "sell" 5 "bookseller" = -1;;
indexOf "xyz" "bookseller" = -1;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALlastIndexOf"><span class="keyword">val</span> lastIndexOf</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<div class="not-examples">
<code class="code">lastIndexOf searchValue s</code> returns the position of the <i>last</i> occurrence of <code class="code">searchValue</code> within <code class="code">s</code>, searching backwards from the end of the string. Returns <code class="code">-1</code> if <code class="code">searchValue</code> is not in <code class="code">s</code>. The return value is always relative to the beginning of the string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> lastIndexOf "ok" "bookseller" = 2;;
lastIndexOf "ee" "beekeeper" = 4;;
lastIndexOf "xyz" "abcdefg" = -1;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALlastIndexOfFrom"><span class="keyword">val</span> lastIndexOfFrom</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<div class="not-examples">
<code class="code">lastIndexOfFrom searchValue start s</code> returns the position of the <i>last</i> occurrence of <code class="code">searchValue</code> within <code class="code">s</code>, searching backwards from the given <code class="code">start</code> position. Returns <code class="code">-1</code> if <code class="code">searchValue</code> is not in <code class="code">s</code>. The return value is always relative to the beginning of the string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> lastIndexOfFrom "ok" 6 "bookseller" = 2;;
lastIndexOfFrom "ee" 8 "beekeeper" = 4;;
lastIndexOfFrom "ee" 3 "beekeeper" = 1;;
lastIndexOfFrom "xyz" 4 "abcdefg" = -1;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALlocaleCompare"><span class="keyword">val</span> localeCompare</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> float</code></pre><div class="info ">
<div class="not-examples">
<code class="code">localeCompare comparison reference</code> returns
<ul>
<li>a negative value if <code class="code">reference</code> comes before <code class="code">comparison</code> in sort order</li>
<li>zero if <code class="code">reference</code> and <code class="code">comparison</code> have the same sort order</li>
<li>a positive value if <code class="code">reference</code> comes after <code class="code">comparison</code> in sort order</li>
</ul>
<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> (localeCompare "ant" "zebra") > 0.0;;
(localeCompare "zebra" "ant") < 0.0;;
(localeCompare "cat" "cat") = 0.0;;
(localeCompare "cat" "CAT") > 0.0;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALmatch_"><span class="keyword">val</span> match_</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> array option</code></pre><div class="info ">
<div class="not-examples">
<code class="code">match regexp str</code> matches a string against the given <code class="code">regexp</code>. If there is no match, it returns <code class="code">None</code>.
For regular expressions without the <code class="code">g</code> modifier, if there is a match, the return value is <code class="code">Some array</code> where the array contains:
<ul>
<li>The entire matched string</li>
<li>Any capture groups if the <code class="code">regexp</code> had parentheses</li>
</ul>
For regular expressions with the <code class="code">g</code> modifier, a matched expression returns <code class="code">Some array</code> with all the matched substrings and no capture groups.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> match [%re "/b[aeiou]t/"] "The better bats" = Some [|"bet"|]
match [%re "/b[aeiou]t/g"] "The better bats" = Some [|"bet";"bat"|]
match [%re "/(\\d+)-(\\d+)-(\\d+)/"] "Today is 2018-04-05." =
Some [|"2018-04-05"; "2018"; "04"; "05"|]
match [%re "/b[aeiou]g/"] "The large container." = None
</code></pre> </pre>
</div>
</div>
<pre><span id="VALnormalize"><span class="keyword">val</span> normalize</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">normalize str</code> returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition.
Consider the character <code class="code">ã</code>, which can be represented as the single codepoint <code class="code">\u00e3</code> or the combination of a lower case letter A <code class="code">\u0061</code> and a combining tilde <code class="code">\u0303</code>. Normalization ensures that both can be stored in an equivalent binary representation.<br>
<div class="tag"> <li><b>See also</b> <a href="https://www.unicode.org/reports/tr15/tr15-45.html">Unicode technical report for details</a></li>
</div>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALnormalizeByForm"><span class="keyword">val</span> normalizeByForm</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">normalize str form</code> (ES2015) returns the normalized Unicode string using the specified form of normalization, which may be one of:
<ul>
<li>"NFC" — Normalization Form Canonical Composition.</li>
<li>"NFD" — Normalization Form Canonical Decomposition.</li>
<li>"NFKC" — Normalization Form Compatibility Composition.</li>
<li>"NFKD" — Normalization Form Compatibility Decomposition.</li>
</ul>
<br>
<div class="tag"> <li><b>See also</b> <a href="https://www.unicode.org/reports/tr15/tr15-45.html">Unicode technical report for details</a></li>
</div>
</div>
</div>
<pre><span id="VALrepeat"><span class="keyword">val</span> repeat</span> : <code class="type">int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">repeat n s</code> returns a string that consists of <code class="code">n</code> repetitions of <code class="code">s</code>. Raises <code class="code">RangeError</code> if <code class="code">n</code> is negative.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> repeat 3 "ha" = "hahaha"
repeat 0 "empty" = ""
</code></pre> </pre>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALreplace"><span class="keyword">val</span> replace</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">replace substr newSubstr string</code> returns a new string which is
identical to <code class="code">string</code> except with the first matching instance of <code class="code">substr</code>
replaced by <code class="code">newSubstr</code>.
<code class="code">substr</code> is treated as a verbatim string to match, not a regular
expression.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> replace "old" "new" "old string" = "new string"
replace "the" "this" "the cat and the dog" = "this cat and the dog"
</code></pre> </pre>
</div>
</div>
<pre><span id="VALreplaceByRe"><span class="keyword">val</span> replaceByRe</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">replaceByRe regex replacement string</code> returns a new string where occurrences matching <code class="code">regex</code>
have been replaced by <code class="code">replacement</code>.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> replaceByRe [%re "/[aeiou]/g"] "x" "vowels be gone" = "vxwxls bx gxnx"
replaceByRe [%re "/(\\w+) (\\w+)/"] "$2, $1" "Juan Fulano" = "Fulano, Juan"
</code></pre> </pre>
</div>
</div>
<pre><span id="VALunsafeReplaceBy0"><span class="keyword">val</span> unsafeReplaceBy0</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -><br> (<a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a>) -><br> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
returns a new string with some or all matches of a pattern with no capturing
parentheses replaced by the value returned from the given function.
The function receives as its parameters the matched string, the offset at which the
match begins, and the whole string being matched<br>
<div class="tag"> <li><b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter">MDN</a></li>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">let str = "beautiful vowels"
let re = [%re "/[aeiou]/g"]
let matchFn matchPart offset wholeString =
Js.String.toUpperCase matchPart
let replaced = Js.String.unsafeReplaceBy0 re matchFn str
let () = Js.log replaced (* prints "bEAUtifUl vOwEls" *)
</code></pre> </pre>
</div>
</div>
<pre><span id="VALunsafeReplaceBy1"><span class="keyword">val</span> unsafeReplaceBy1</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -><br> (<a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a>) -><br> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
returns a new string with some or all matches of a pattern with one set of capturing
parentheses replaced by the value returned from the given function.
The function receives as its parameters the matched string, the captured string,
the offset at which the match begins, and the whole string being matched.<br>
<div class="tag"> <li><b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter">MDN</a></li>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">let str = "increment 23"
let re = [%re "/increment (\\d+)/g"]
let matchFn matchPart p1 offset wholeString =
wholeString ^ " is " ^ (string_of_int ((int_of_string p1) + 1))
let replaced = Js.String.unsafeReplaceBy1 re matchFn str
let () = Js.log replaced (* prints "increment 23 is 24" *)
</code></pre> </pre>
</div>
</div>
<pre><span id="VALunsafeReplaceBy2"><span class="keyword">val</span> unsafeReplaceBy2</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -><br> (<a href="Js_string.html#TYPEt">t</a> -><br> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a>) -><br> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
returns a new string with some or all matches of a pattern with two sets of capturing
parentheses replaced by the value returned from the given function.
The function receives as its parameters the matched string, the captured strings,
the offset at which the match begins, and the whole string being matched.<br>
<div class="tag"> <li><b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter">MDN</a></li>
</div>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">let str = "7 times 6"
let re = [%re "/(\\d+) times (\\d+)/"]
let matchFn matchPart p1 p2 offset wholeString =
string_of_int ((int_of_string p1) * (int_of_string p2))
let replaced = Js.String.unsafeReplaceBy2 re matchFn str
let () = Js.log replaced (* prints "42" *)
</code></pre> </pre>
</div>
</div>
<pre><span id="VALunsafeReplaceBy3"><span class="keyword">val</span> unsafeReplaceBy3</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -><br> (<a href="Js_string.html#TYPEt">t</a> -><br> <a href="Js_string.html#TYPEt">t</a> -><br> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a>) -><br> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
returns a new string with some or all matches of a pattern with three sets of capturing
parentheses replaced by the value returned from the given function.
The function receives as its parameters the matched string, the captured strings,
the offset at which the match begins, and the whole string being matched.<br>
<div class="tag"> <li><b>See also</b> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter">MDN</a></li>
</div>
</div>
</div>
<pre><span id="VALsearch"><span class="keyword">val</span> search</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -> <a href="Js_string.html#TYPEt">t</a> -> int</code></pre><div class="info ">
<div class="not-examples">
<code class="code">search regexp str</code> returns the starting position of the first match of <code class="code">regexp</code> in the given <code class="code">str</code>, or -1 if there is no match.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code">search [%re "/\\d+/"] "testing 1 2 3" = 8;;
search [%re "/\\d+/"] "no numbers" = -1;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALslice"><span class="keyword">val</span> slice</span> : <code class="type">from:int -> to_:int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">slice from:n1 to_:n2 str</code> returns the substring of <code class="code">str</code> starting at character <code class="code">n1</code> up to but not including <code class="code">n2</code>
If either <code class="code">n1</code> or <code class="code">n2</code> is negative, then it is evaluated as <code class="code">length str - n1</code> (or <code class="code">length str - n2</code>.
If <code class="code">n2</code> is greater than the length of <code class="code">str</code>, then it is treated as <code class="code">length str</code>.
If <code class="code">n1</code> is greater than <code class="code">n2</code>, <code class="code">slice</code> returns the empty string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> slice ~from:2 ~to_:5 "abcdefg" == "cde";;
slice ~from:2 ~to_:9 "abcdefg" == "cdefg";;
slice ~from:(-4) ~to_:(-2) "abcdefg" == "de";;
slice ~from:5 ~to_:1 "abcdefg" == "";;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALsliceToEnd"><span class="keyword">val</span> sliceToEnd</span> : <code class="type">from:int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">sliceToEnd from: n str</code> returns the substring of <code class="code">str</code> starting at character <code class="code">n</code> to the end of the string
If <code class="code">n</code> is negative, then it is evaluated as <code class="code">length str - n</code>.
If <code class="code">n</code> is greater than the length of <code class="code">str</code>, then <code class="code">sliceToEnd</code> returns the empty string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> sliceToEnd ~from: 4 "abcdefg" == "efg";;
sliceToEnd ~from: (-2) "abcdefg" == "fg";;
sliceToEnd ~from: 7 "abcdefg" == "";;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALsplit"><span class="keyword">val</span> split</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> array</code></pre><div class="info ">
<div class="not-examples">
<code class="code">split delimiter str</code> splits the given <code class="code">str</code> at every occurrence of <code class="code">delimiter</code> and returns an
array of the resulting substrings.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> split "-" "2018-01-02" = [|"2018"; "01"; "02"|];;
split "," "a,b,,c" = [|"a"; "b"; ""; "c"|];;
split "::" "good::bad as great::awful" = [|"good"; "bad as great"; "awful"|];;
split ";" "has-no-delimiter" = [|"has-no-delimiter"|];;
</code></pre>; </pre>
</div>
</div>
<pre><span id="VALsplitAtMost"><span class="keyword">val</span> splitAtMost</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> limit:int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> array</code></pre><div class="info ">
<div class="not-examples">
<code class="code">splitAtMost delimiter ~limit: n str</code> splits the given <code class="code">str</code> at every occurrence of <code class="code">delimiter</code> and returns an array of the first <code class="code">n</code> resulting substrings. If <code class="code">n</code> is negative or greater than the number of substrings, the array will contain all the substrings.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> splitAtMost "/" ~limit: 3 "ant/bee/cat/dog/elk" = [|"ant"; "bee"; "cat"|];;
splitAtMost "/" ~limit: 0 "ant/bee/cat/dog/elk" = [| |];;
splitAtMost "/" ~limit: 9 "ant/bee/cat/dog/elk" = [|"ant"; "bee"; "cat"; "dog"; "elk"|];;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALsplitLimited"><span class="keyword">val</span> splitLimited</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> array</code></pre><div class="info ">
<div class="not-examples">
Deprecated - Please use <code class="code">splitAtMost</code><br>
</div>
</div>
<pre><span id="VALsplitByRe"><span class="keyword">val</span> splitByRe</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> option array</code></pre><div class="info ">
<div class="not-examples">
<code class="code">splitByRe regex str</code> splits the given <code class="code">str</code> at every occurrence of <code class="code">regex</code> and returns an
array of the resulting substrings.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> splitByRe [%re "/\\s*[,;]\\s*/"] "art; bed , cog ;dad" = [|Some "art"; Some "bed"; Some "cog"; Some "dad"|];;
splitByRe [%re "/[,;]/"] "has:no:match" = [|Some "has:no:match"|];;
splitByRe [%re "/(#)(:)?/"] "a#b#:c" = [|Some "a"; Some "#"; None; Some "b"; Some "#"; Some ":"; Some "c"|];;
</code></pre>; </pre>
</div>
</div>
<pre><span id="VALsplitByReAtMost"><span class="keyword">val</span> splitByReAtMost</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -> limit:int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> option array</code></pre><div class="info ">
<div class="not-examples">
<code class="code">splitByReAtMost regex ~limit: n str</code> splits the given <code class="code">str</code> at every occurrence of <code class="code">regex</code> and returns an
array of the first <code class="code">n</code> resulting substrings. If <code class="code">n</code> is negative or greater than the number of substrings, the array will contain all the substrings.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> splitByReAtMost [%re "/\\s*:\\s*/"] ~limit: 3 "one: two: three: four" = [|Some "one"; Some "two"; Some "three"|];;
splitByReAtMost [%re "/\\s*:\\s*/"] ~limit: 0 "one: two: three: four" = [| |];;
splitByReAtMost [%re "/\\s*:\\s*/"] ~limit: 8 "one: two: three: four" = [|Some "one"; Some "two"; Some "three"; Some "four"|];;
splitByReAtMost [%re "/(#)(:)?/"] ~limit:3 "a#b#:c" = [|Some "a"; Some "#"; None|];;
</code></pre>; </pre>
</div>
</div>
<pre><span id="VALsplitRegexpLimited"><span class="keyword">val</span> splitRegexpLimited</span> : <code class="type"><a href="Js_re.html#TYPEt">Js_re.t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> array</code></pre><div class="info ">
<div class="not-examples">
Deprecated - Please use <code class="code">splitByReAtMost</code><br>
</div>
</div>
<pre><span id="VALstartsWith"><span class="keyword">val</span> startsWith</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> bool</code></pre><div class="info ">
<div class="not-examples">
ES2015:
<code class="code">startsWith substr str</code> returns <code class="code">true</code> if the <code class="code">str</code> starts with <code class="code">substr</code>, <code class="code">false</code> otherwise.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> startsWith "Buckle" "BuckleScript" = true;;
startsWith "" "BuckleScript" = true;;
startsWith "Buckle" "JavaScript" = false;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALstartsWithFrom"><span class="keyword">val</span> startsWithFrom</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> int -> <a href="Js_string.html#TYPEt">t</a> -> bool</code></pre><div class="info ">
<div class="not-examples">
ES2015:
<code class="code">startsWithFrom substr n str</code> returns <code class="code">true</code> if the <code class="code">str</code> starts with <code class="code">substr</code> starting at position <code class="code">n</code>, <code class="code">false</code> otherwise. If <code class="code">n</code> is negative, the search starts at the beginning of <code class="code">str</code>.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> startsWithFrom "kle" 3 "BuckleScript" = true;;
startsWithFrom "" 3 "BuckleScript" = true;;
startsWithFrom "Buckle" 2 "JavaScript" = false;;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALsubstr"><span class="keyword">val</span> substr</span> : <code class="type">from:int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">substr ~from: n str</code> returns the substring of <code class="code">str</code> from position <code class="code">n</code> to the end of the string.
If <code class="code">n</code> is less than zero, the starting position is the length of <code class="code">str</code> - <code class="code">n</code>.
If <code class="code">n</code> is greater than or equal to the length of <code class="code">str</code>, returns the empty string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> substr ~from: 3 "abcdefghij" = "defghij"
substr ~from: (-3) "abcdefghij" = "hij"
substr ~from: 12 "abcdefghij" = ""
</code></pre> </pre>
</div>
</div>
<pre><span id="VALsubstrAtMost"><span class="keyword">val</span> substrAtMost</span> : <code class="type">from:int -> length:int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">substrAtMost ~from: pos ~length: n str</code> returns the substring of <code class="code">str</code> of length <code class="code">n</code> starting at position <code class="code">pos</code>.
If <code class="code">pos</code> is less than zero, the starting position is the length of <code class="code">str</code> - <code class="code">pos</code>.
If <code class="code">pos</code> is greater than or equal to the length of <code class="code">str</code>, returns the empty string.
If <code class="code">n</code> is less than or equal to zero, returns the empty string.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> substrAtMost ~from: 3 ~length: 4 "abcdefghij" = "defghij"
substrAtMost ~from: (-3) ~length: 4 "abcdefghij" = "hij"
substrAtMost ~from: 12 ~ length: 2 "abcdefghij" = ""
</code></pre> </pre>
</div>
</div>
<pre><span id="VALsubstring"><span class="keyword">val</span> substring</span> : <code class="type">from:int -> to_:int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">substring ~from: start ~to_: finish str</code> returns characters <code class="code">start</code> up to but not including <code class="code">finish</code> from <code class="code">str</code>.
If <code class="code">start</code> is less than zero, it is treated as zero.
If <code class="code">finish</code> is zero or negative, the empty string is returned.
If <code class="code">start</code> is greater than <code class="code">finish</code>, the start and finish points are swapped.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> substring ~from: 3 ~to_: 6 "playground" = "ygr";;
substring ~from: 6 ~to_: 3 "playground" = "ygr";;
substring ~from: 4 ~to_: 12 "playground" = "ground";;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALsubstringToEnd"><span class="keyword">val</span> substringToEnd</span> : <code class="type">from:int -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">substringToEnd ~from: start str</code> returns the substring of <code class="code">str</code> from position <code class="code">start</code> to the end.
If <code class="code">start</code> is less than or equal to zero, the entire string is returned.
If <code class="code">start</code> is greater than or equal to the length of <code class="code">str</code>, the empty string is returned.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> substringToEnd ~from: 4 "playground" = "ground";;
substringToEnd ~from: (-3) "playground" = "playground";;
substringToEnd ~from: 12 "playground" = "";
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoLowerCase"><span class="keyword">val</span> toLowerCase</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">toLowerCase str</code> converts <code class="code">str</code> to lower case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can give different results depending upon context, for example with the Greek letter sigma, which has two different lower case forms when it is the last character in a string or not.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> toLowerCase "ABC" = "abc";;
toLowerCase {js|ΣΠ|js} = {js|σπ|js};;
toLowerCase {js|ΠΣ|js} = {js|πς|js};;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoLocaleLowerCase"><span class="keyword">val</span> toLocaleLowerCase</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">toLocaleLowerCase str</code> converts <code class="code">str</code> to lower case using the current locale<br>
</div>
</div>
<pre><span id="VALtoUpperCase"><span class="keyword">val</span> toUpperCase</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">toUpperCase str</code> converts <code class="code">str</code> to upper case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can expand the number of letters in the result; for example the German <code class="code">ß</code> capitalizes to two <code class="code">S</code>es in a row.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> toUpperCase "abc" = "ABC";;
toUpperCase {js|Straße|js} = {js|STRASSE|js};;
toLowerCase {js|πς|js} = {js|ΠΣ|js};;
</code></pre> </pre>
</div>
</div>
<pre><span id="VALtoLocaleUpperCase"><span class="keyword">val</span> toLocaleUpperCase</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">toLocaleUpperCase str</code> converts <code class="code">str</code> to upper case using the current locale<br>
</div>
</div>
<pre><span id="VALtrim"><span class="keyword">val</span> trim</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">trim str</code> returns a string that is <code class="code">str</code> with whitespace stripped from both ends. Internal whitespace is not removed.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> trim " abc def " = "abc def"
trim "\n\r\t abc def \n\n\t\r " = "abc def"
</code></pre> </pre>
</div>
</div>
<pre><span id="VALanchor"><span class="keyword">val</span> anchor</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">anchor anchorName anchorText</code> creates a string with an HTML <code class="code"><a></code> element with <code class="code">name</code> attribute of <code class="code">anchorName</code> and <code class="code">anchorText</code> as its content.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> anchor "page1" "Page One" = "<a name=\"page1\">Page One</a>"
</code></pre> </pre>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALlink"><span class="keyword">val</span> link</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a></code></pre><div class="info ">
<div class="not-examples">
<code class="code">link urlText linkText</code> creates a string withan HTML <code class="code"><a></code> element with <code class="code">href</code> attribute of <code class="code">urlText</code> and <code class="code">linkText</code> as its content.<br>
</div>
<div class="examples">
<pre class="example"> <pre class="codepre"><code class="code"> link "page2.html" "Go to page two" = "<a href=\"page2.html\">Go to page two</a>"
</code></pre> </pre>
</div>
</div>
<p>ES2015</p>
<pre><span id="VALcastToArrayLike"><span class="keyword">val</span> castToArrayLike</span> : <code class="type"><a href="Js_string.html#TYPEt">t</a> -> <a href="Js_string.html#TYPEt">t</a> <a href="Js_array2.html#TYPEarray_like">Js_array2.array_like</a></code></pre></body></html>