1StringLabels(3)                  OCaml library                 StringLabels(3)
2
3
4

NAME

6       StringLabels - String operations.
7

Module

9       Module   StringLabels
10

Documentation

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