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