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