1Stdlib.String(3) OCaml library Stdlib.String(3)
2
3
4
6 Stdlib.String - no description
7
9 Module Stdlib.String
10
12 Module String
13 : (module Stdlib__string)
14
15
16
17
18
19
20
21
22 val length : string -> int
23
24 Return the length (number of characters) of the given string.
25
26
27
28 val get : string -> int -> char
29
30
31 String.get s n returns the character at index n in string s . You can
32 also write s.[n] instead of String.get s n .
33
34 Raise Invalid_argument if n not a valid index in s .
35
36
37
38 val set : bytes -> int -> char -> unit
39
40 Deprecated. This is a deprecated alias of Bytes.set .
41
42
43
44
45 String.set s n c modifies byte sequence s in place, replacing the byte
46 at index n with c . You can also write s.[n] <- c instead of
47 String.set s n c .
48
49 Raise Invalid_argument if n is not a valid index in s .
50
51
52
53 val create : int -> bytes
54
55 Deprecated. This is a deprecated alias of Bytes.create .
56
57
58
59
60 String.create n returns a fresh byte sequence of length n . The
61 sequence is uninitialized and contains arbitrary bytes.
62
63 Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
64
65
66
67 val make : int -> char -> string
68
69
70 String.make n c returns a fresh string of length n , filled with the
71 character c .
72
73 Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
74
75
76
77 val init : int -> (int -> char) -> string
78
79
80 String.init n f returns a string of length n , with character i ini‐
81 tialized to the result of f i (called in increasing index order).
82
83 Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
84
85
86 Since 4.02.0
87
88
89
90 val copy : string -> string
91
92 Deprecated. Because strings are immutable, it doesn't make much sense
93 to make identical copies of them.
94
95
96 Return a copy of the given string.
97
98
99
100 val sub : string -> int -> int -> string
101
102
103 String.sub s start len returns a fresh string of length len , contain‐
104 ing the substring of s that starts at position start and has length len
105 .
106
107 Raise Invalid_argument if start and len do not designate a valid sub‐
108 string of s .
109
110
111
112 val fill : bytes -> int -> int -> char -> unit
113
114 Deprecated. This is a deprecated alias of Bytes.fill .
115
116
117
118
119 String.fill s start len c modifies byte sequence s in place, replacing
120 len bytes with c , starting at start .
121
122 Raise Invalid_argument if start and len do not designate a valid range
123 of s .
124
125
126
127 val blit : string -> int -> bytes -> int -> int -> unit
128
129 Same as Bytes.blit_string .
130
131
132
133 val concat : string -> string list -> string
134
135
136 String.concat sep sl concatenates the list of strings sl , inserting
137 the separator string sep between each.
138
139 Raise Invalid_argument if the result is longer than
140 Sys.max_string_length bytes.
141
142
143
144 val iter : (char -> unit) -> string -> unit
145
146
147 String.iter f s applies function f in turn to all the characters of s .
148 It is equivalent to f s.[0]; f s.[1]; ...; f s.[String.length s - 1];
149 () .
150
151
152
153 val iteri : (int -> char -> unit) -> string -> unit
154
155 Same as String.iter , but the function is applied to the index of the
156 element as first argument (counting from 0), and the character itself
157 as second argument.
158
159
160 Since 4.00.0
161
162
163
164 val map : (char -> char) -> string -> string
165
166
167 String.map f s applies function f in turn to all the characters of s
168 (in increasing index order) and stores the results in a new string that
169 is returned.
170
171
172 Since 4.00.0
173
174
175
176 val mapi : (int -> char -> char) -> string -> string
177
178
179 String.mapi f s calls f with each character of s and its index (in
180 increasing index order) and stores the results in a new string that is
181 returned.
182
183
184 Since 4.02.0
185
186
187
188 val trim : string -> string
189
190 Return a copy of the argument, without leading and trailing whitespace.
191 The characters regarded as whitespace are: ' ' , '\012' , '\n' , '\r' ,
192 and '\t' . If there is neither leading nor trailing whitespace charac‐
193 ter in the argument, return the original string itself, not a copy.
194
195
196 Since 4.00.0
197
198
199
200 val escaped : string -> string
201
202 Return a copy of the argument, with special characters represented by
203 escape sequences, following the lexical conventions of OCaml. All
204 characters outside the ASCII printable range (32..126) are escaped, as
205 well as backslash and double-quote.
206
207 If there is no special character in the argument that needs escaping,
208 return the original string itself, not a copy.
209
210 Raise Invalid_argument if the result is longer than
211 Sys.max_string_length bytes.
212
213 The function Scanf.unescaped is a left inverse of escaped , i.e.
214 Scanf.unescaped (escaped s) = s for any string s (unless escape s
215 fails).
216
217
218
219 val index : string -> char -> int
220
221
222 String.index s c returns the index of the first occurrence of character
223 c in string s .
224
225 Raise Not_found if c does not occur in s .
226
227
228
229 val index_opt : string -> char -> int option
230
231
232 String.index_opt s c returns the index of the first occurrence of char‐
233 acter c in string s , or None if c does not occur in s .
234
235
236 Since 4.05
237
238
239
240 val rindex : string -> char -> int
241
242
243 String.rindex s c returns the index of the last occurrence of character
244 c in string s .
245
246 Raise Not_found if c does not occur in s .
247
248
249
250 val rindex_opt : string -> char -> int option
251
252
253 String.rindex_opt s c returns the index of the last occurrence of char‐
254 acter c in string s , or None if c does not occur in s .
255
256
257 Since 4.05
258
259
260
261 val index_from : string -> int -> char -> int
262
263
264 String.index_from s i c returns the index of the first occurrence of
265 character c in string s after position i . String.index s c is equiva‐
266 lent to String.index_from s 0 c .
267
268 Raise Invalid_argument if i is not a valid position in s . Raise
269 Not_found if c does not occur in s after position i .
270
271
272
273 val index_from_opt : string -> int -> char -> int option
274
275
276 String.index_from_opt s i c returns the index of the first occurrence
277 of character c in string s after position i or None if c does not occur
278 in s after position i .
279
280
281 String.index_opt s c is equivalent to String.index_from_opt s 0 c .
282 Raise Invalid_argument if i is not a valid position in s .
283
284
285 Since 4.05
286
287
288
289 val rindex_from : string -> int -> char -> int
290
291
292 String.rindex_from s i c returns the index of the last occurrence of
293 character c in string s before position i+1 . String.rindex s c is
294 equivalent to String.rindex_from s (String.length s - 1) c .
295
296 Raise Invalid_argument if i+1 is not a valid position in s . Raise
297 Not_found if c does not occur in s before position i+1 .
298
299
300
301 val rindex_from_opt : string -> int -> char -> int option
302
303
304 String.rindex_from_opt s i c returns the index of the last occurrence
305 of character c in string s before position i+1 or None if c does not
306 occur in s before position i+1 .
307
308
309 String.rindex_opt s c is equivalent to String.rindex_from_opt s
310 (String.length s - 1) c .
311
312 Raise Invalid_argument if i+1 is not a valid position in s .
313
314
315 Since 4.05
316
317
318
319 val contains : string -> char -> bool
320
321
322 String.contains s c tests if character c appears in the string s .
323
324
325
326 val contains_from : string -> int -> char -> bool
327
328
329 String.contains_from s start c tests if character c appears in s after
330 position start . String.contains s c is equivalent to String.con‐
331 tains_from s 0 c .
332
333 Raise Invalid_argument if start is not a valid position in s .
334
335
336
337 val rcontains_from : string -> int -> char -> bool
338
339
340 String.rcontains_from s stop c tests if character c appears in s before
341 position stop+1 .
342
343 Raise Invalid_argument if stop < 0 or stop+1 is not a valid position in
344 s .
345
346
347
348 val uppercase : string -> string
349
350 Deprecated. Functions operating on Latin-1 character set are depre‐
351 cated.
352
353
354 Return a copy of the argument, with all lowercase letters translated to
355 uppercase, including accented letters of the ISO Latin-1 (8859-1) char‐
356 acter set.
357
358
359
360 val lowercase : string -> string
361
362 Deprecated. Functions operating on Latin-1 character set are depre‐
363 cated.
364
365
366 Return a copy of the argument, with all uppercase letters translated to
367 lowercase, including accented letters of the ISO Latin-1 (8859-1) char‐
368 acter set.
369
370
371
372 val capitalize : string -> string
373
374 Deprecated. Functions operating on Latin-1 character set are depre‐
375 cated.
376
377
378 Return a copy of the argument, with the first character set to upper‐
379 case, using the ISO Latin-1 (8859-1) character set..
380
381
382
383 val uncapitalize : string -> string
384
385 Deprecated. Functions operating on Latin-1 character set are depre‐
386 cated.
387
388
389 Return a copy of the argument, with the first character set to lower‐
390 case, using the ISO Latin-1 (8859-1) character set..
391
392
393
394 val uppercase_ascii : string -> string
395
396 Return a copy of the argument, with all lowercase letters translated to
397 uppercase, using the US-ASCII character set.
398
399
400 Since 4.03.0
401
402
403
404 val lowercase_ascii : string -> string
405
406 Return a copy of the argument, with all uppercase letters translated to
407 lowercase, using the US-ASCII character set.
408
409
410 Since 4.03.0
411
412
413
414 val capitalize_ascii : string -> string
415
416 Return a copy of the argument, with the first character set to upper‐
417 case, using the US-ASCII character set.
418
419
420 Since 4.03.0
421
422
423
424 val uncapitalize_ascii : string -> string
425
426 Return a copy of the argument, with the first character set to lower‐
427 case, using the US-ASCII character set.
428
429
430 Since 4.03.0
431
432
433 type t = string
434
435
436 An alias for the type of strings.
437
438
439
440 val compare : t -> t -> int
441
442 The comparison function for strings, with the same specification as
443 compare . Along with the type t , this function compare allows the
444 module String to be passed as argument to the functors Set.Make and
445 Map.Make .
446
447
448
449 val equal : t -> t -> bool
450
451 The equal function for strings.
452
453
454 Since 4.03.0
455
456
457
458 val split_on_char : char -> string -> string list
459
460
461 String.split_on_char sep s returns the list of all (possibly empty)
462 substrings of s that are delimited by the sep character.
463
464 The function's output is specified by the following invariants:
465
466
467 -The list is not empty.
468
469 -Concatenating its elements using sep as a separator returns a string
470 equal to the input ( String.concat (String.make 1 sep)
471 (String.split_on_char sep s) = s ).
472
473 -No string in the result contains the sep character.
474
475
476
477 Since 4.04.0
478
479
480
481
482 Iterators
483 val to_seq : t -> char Seq.t
484
485 Iterate on the string, in increasing index order. Modifications of the
486 string during iteration will be reflected in the iterator.
487
488
489 Since 4.07
490
491
492
493 val to_seqi : t -> (int * char) Seq.t
494
495 Iterate on the string, in increasing order, yielding indices along
496 chars
497
498
499 Since 4.07
500
501
502
503 val of_seq : char Seq.t -> t
504
505 Create a string from the generator
506
507
508 Since 4.07
509
510
511
512
513
514OCamldoc 2020-02-27 Stdlib.String(3)