1String(3) OCaml library String(3)
2
3
4
6 String - String operations.
7
9 Module String
10
12 Module String
13 : sig end
14
15
16 String operations.
17
18
19
20
21
22
23
24 val length : string -> int
25
26 Return the length (number of characters) of the given string.
27
28
29
30
31 val get : string -> int -> char
32
33
34 String.get s n returns character number n in string s . The first
35 character is character number 0. The last character is character num‐
36 ber String.length s - 1 . You can also write s.[n] instead of
37 String.get s n .
38
39 Raise Invalid_argument index out of bounds if n is outside the range 0
40 to (String.length s - 1) .
41
42
43
44
45 val set : string -> int -> char -> unit
46
47
48 String.set s n c modifies string s in place, replacing the character
49 number n by c . You can also write s.[n] <- c instead of String.set s
50 n c . Raise Invalid_argument index out of bounds if n is outside the
51 range 0 to (String.length s - 1) .
52
53
54
55
56 val create : int -> string
57
58
59 String.create n returns a fresh string of length n . The string ini‐
60 tially contains arbitrary characters. Raise Invalid_argument if n < 0
61 or n > Sys.max_string_length .
62
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 . Raise Invalid_argument if n < 0 or n >
71 Sys.max_string_length .
72
73
74
75
76 val copy : string -> string
77
78 Return a copy of the given string.
79
80
81
82
83 val sub : string -> int -> int -> string
84
85
86 String.sub s start len returns a fresh string of length len , contain‐
87 ing the characters number start to start + len - 1 of string s . Raise
88 Invalid_argument if start and len do not designate a valid substring of
89 s ; that is, if start < 0 , or len < 0 , or start + len > String.length
90 s .
91
92
93
94
95 val fill : string -> int -> int -> char -> unit
96
97
98 String.fill s start len c modifies string s in place, replacing the
99 characters number start to start + len - 1 by c . Raise Invalid_argu‐
100 ment if start and len do not designate a valid substring of s .
101
102
103
104
105 val blit : string -> int -> string -> int -> int -> unit
106
107
108 String.blit src srcoff dst dstoff len copies len characters from string
109 src , starting at character number srcoff , to string dst , starting at
110 character number dstoff . It works correctly even if src and dst are
111 the same string, and the source and destination chunks overlap. Raise
112 Invalid_argument if srcoff and len do not designate a valid substring
113 of src , or if dstoff and len do not designate a valid substring of dst
114 .
115
116
117
118
119 val concat : string -> string list -> string
120
121
122 String.concat sep sl concatenates the list of strings sl , inserting
123 the separator string sep between each.
124
125
126
127
128 val iter : (char -> unit) -> string -> unit
129
130
131 String.iter f s applies function f in turn to all the characters of s .
132 It is equivalent to f s.[0]; f s.[1]; ...; f s.[String.length s - 1];
133 () .
134
135
136
137
138 val escaped : string -> string
139
140 Return a copy of the argument, with special characters represented by
141 escape sequences, following the lexical conventions of Objective Caml.
142 If there is no special character in the argument, return the original
143 string itself, not a copy.
144
145
146
147
148 val index : string -> char -> int
149
150
151 String.index s c returns the position of the leftmost occurrence of
152 character c in string s . Raise Not_found if c does not occur in s .
153
154
155
156
157 val rindex : string -> char -> int
158
159
160 String.rindex s c returns the position of the rightmost occurrence of
161 character c in string s . Raise Not_found if c does not occur in s .
162
163
164
165
166 val index_from : string -> int -> char -> int
167
168 Same as String.index , but start searching at the character position
169 given as second argument. String.index s c is equivalent to
170 String.index_from s 0 c .
171
172
173
174
175 val rindex_from : string -> int -> char -> int
176
177 Same as String.rindex , but start searching at the character position
178 given as second argument. String.rindex s c is equivalent to
179 String.rindex_from s (String.length s - 1) c .
180
181
182
183
184 val contains : string -> char -> bool
185
186
187 String.contains s c tests if character c appears in the string s .
188
189
190
191
192 val contains_from : string -> int -> char -> bool
193
194
195 String.contains_from s start c tests if character c appears in the sub‐
196 string of s starting from start to the end of s . Raise Invalid_argu‐
197 ment if start is not a valid index of s .
198
199
200
201
202 val rcontains_from : string -> int -> char -> bool
203
204
205 String.rcontains_from s stop c tests if character c appears in the sub‐
206 string of s starting from the beginning of s to index stop . Raise
207 Invalid_argument if stop is not a valid index of s .
208
209
210
211
212 val uppercase : string -> string
213
214 Return a copy of the argument, with all lowercase letters translated to
215 uppercase, including accented letters of the ISO Latin-1 (8859-1) char‐
216 acter set.
217
218
219
220
221 val lowercase : string -> string
222
223 Return a copy of the argument, with all uppercase letters translated to
224 lowercase, including accented letters of the ISO Latin-1 (8859-1) char‐
225 acter set.
226
227
228
229
230 val capitalize : string -> string
231
232 Return a copy of the argument, with the first character set to upper‐
233 case.
234
235
236
237
238 val uncapitalize : string -> string
239
240 Return a copy of the argument, with the first character set to lower‐
241 case.
242
243
244
245 type t = string
246
247
248 An alias for the type of strings.
249
250
251
252
253 val compare : t -> t -> int
254
255 The comparison function for strings, with the same specification as
256 Pervasives.compare . Along with the type t , this function compare
257 allows the module String to be passed as argument to the functors
258 Set.Make and Map.Make .
259
260
261
262
263
264
265OCamldoc 2007-05-24 String(3)