File: string.html

package info (click to toggle)
erlang-doc-html 1%3A8.0-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 18,028 kB
  • ctags: 7,419
  • sloc: perl: 1,841; ansic: 323; erlang: 155
file content (292 lines) | stat: -rw-r--r-- 11,120 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<HTML>
<HEAD>
<!-- refpage -->
<TITLE>string</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>


<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Erlang Systems]" SRC="min_head.gif"></A>
<H1>string</H1>
</CENTER>
<H3>MODULE</H3>
<UL>
string</UL>
<H3>MODULE SUMMARY</H3>
<UL>
String Processing Functions</UL>
<H3>DESCRIPTION</H3>
<UL>
<P>This module contains functions for string processing.
</UL>
<H3>EXPORTS</H3>
<P><A NAME="len%1"><STRONG><CODE>len(String) -&#62; Length</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
<STRONG><CODE>Length = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the number of characters in the string.
</UL>
<P><A NAME="equal%2"><STRONG><CODE>equal(String1, String2) -&#62; bool()</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String1 = String2 = string()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Tests whether two strings are equal. Returns <CODE>true</CODE> if
they are, otherwise <CODE>false</CODE>.
</UL>
<P><A NAME="concat%2"><STRONG><CODE>concat(String1, String2) -&#62; String3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String1 = String2 = String3 = string()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Concatenates two strings to form a new string. Returns the
new string.
</UL>
<P><A NAME="chr%2"><STRONG><CODE>chr(String, Character) -&#62; Index</CODE></STRONG></A><BR>
<A NAME="rchr%2"><STRONG><CODE>rchr(String, Character) -&#62; Index</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
<STRONG><CODE>Index = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the index of the first/last occurrence of
<CODE>Character</CODE> in <CODE>String</CODE>. <CODE>0</CODE> is returned if <CODE>Character</CODE> does not
occur.
</UL>
<P><A NAME="str%2"><STRONG><CODE>str(String, SubString) -&#62; Index</CODE></STRONG></A><BR>
<A NAME="rstr%2"><STRONG><CODE>rstr(String, SubString) -&#62; Index</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = SubString = string()</CODE></STRONG><BR>
<STRONG><CODE>Index = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the position where the first/last occurrence of
<CODE>SubString</CODE> begins in <CODE>String</CODE>. <CODE>0</CODE> is returned if <CODE>SubString</CODE>
does not exist in <CODE>String</CODE>.
For example:<PRE>&#62; string:str(&#34; Hello Hello World World &#34;, &#34;Hello World&#34;).
8</PRE></UL>
<P><A NAME="span%2"><STRONG><CODE>span(String, Chars) -&#62; Length </CODE></STRONG></A><BR>
<A NAME="cspan%2"><STRONG><CODE>cspan(String, Chars) -&#62; Length</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = Chars = string()</CODE></STRONG><BR>
<STRONG><CODE>Length = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the length of the maximum initial segment of
String, which consists entirely of characters from (not
from) Chars.
<P>For example:<PRE>&#62; string:span(&#34;\t    abcdef&#34;, &#34; \t&#34;).
5
&#62; string:cspan(&#34;\t    abcdef&#34;, &#34; \t&#34;).
0</PRE></UL>
<P><A NAME="substr%2"><STRONG><CODE>substr(String, Start) -&#62; SubString</CODE></STRONG></A><BR>
<A NAME="substr%3"><STRONG><CODE>substr(String, Start, Length) -&#62; Substring</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = SubString = string()</CODE></STRONG><BR>
<STRONG><CODE>Start = Length = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a substring of <CODE>String</CODE>, starting at the
position <CODE>Start</CODE>, and ending at the end of the string or
at length <CODE>Length</CODE>.
<P>For example:<PRE>&#62; substr(&#34;Hello World&#34;, 4, 5).
&#34;lo Wo&#34;</PRE></UL>
<P><A NAME="tokens%2"><STRONG><CODE>tokens(String, SeparatorList) -&#62; Tokens</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = SeparatorList = string()</CODE></STRONG><BR>
<STRONG><CODE>Tokens = [string()]</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a list of tokens in <CODE>String</CODE>, separated by the
characters in <CODE>SeparatorList</CODE>.
<P>For example:<PRE>&#62; tokens(&#34;abc defxxghix jkl&#34;, &#34;x &#34;).
[&#34;abc&#34;, &#34;def&#34;, &#34;ghi&#34;, &#34;jkl&#34;]</PRE></UL>
<P><A NAME="chars%2"><STRONG><CODE>chars(Character, Number) -&#62; String</CODE></STRONG></A><BR>
<A NAME="chars%3"><STRONG><CODE>chars(Character, Number, Tail) -&#62; String</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a string consisting of <CODE>Number</CODE> of characters
<CODE>Character</CODE>. Optionally, the string can end with the
string <CODE>Tail</CODE>.
</UL>
<P><A NAME="copies%2"><STRONG><CODE>copies(String, Number) -&#62; Copies</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = Copies = string()</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a string containing <CODE>String</CODE> repeated
<CODE>Number</CODE> times.
</UL>
<P><A NAME="words%1"><STRONG><CODE>words(String) -&#62; Count</CODE></STRONG></A><BR>
<A NAME="words%2"><STRONG><CODE>words(String, Character) -&#62; Count</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
<STRONG><CODE>Count = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the number of words in <CODE>String</CODE>, separated by
blanks or <CODE>Character</CODE>.
<P>For example:<PRE>&#62; words(&#34; Hello old boy!&#34;, $o).
4</PRE></UL>
<P><A NAME="sub_word%2"><STRONG><CODE>sub_word(String, Number) -&#62; Word</CODE></STRONG></A><BR>
<A NAME="sub_word%3"><STRONG><CODE>sub_word(String, Number, Character) -&#62; Word</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = Word = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the word in position <CODE>Number</CODE> of <CODE>String</CODE>.
Words are separated by blanks or <CODE>Character</CODE>s.
<P>For example:<PRE>&#62; string:sub_word(&#34; Hello old boy !&#34;,3,$o).
&#34;ld b&#34;</PRE></UL>
<P><A NAME="strip%1"><STRONG><CODE>strip(String) -&#62; Stripped</CODE></STRONG></A><BR>
<A NAME="strip%2"><STRONG><CODE>strip(String, Direction) -&#62; Stripped</CODE></STRONG></A><BR>
<A NAME="strip%3"><STRONG><CODE>strip(String, Direction, Character) -&#62; Stripped</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = Stripped = string()</CODE></STRONG><BR>
<STRONG><CODE>Direction = left | right | both</CODE></STRONG><BR>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a string, where leading and/or trailing blanks or a
number of <CODE>Character</CODE> have been removed.
<CODE>Direction</CODE> can be <CODE>left</CODE>, <CODE>right</CODE>, or
<CODE>both</CODE> and indicates from which direction blanks are to be
removed. The function <CODE>strip/1</CODE> is equivalent to
<CODE>strip(String, both)</CODE>.
<P>For example:<PRE>&#62; string:strip(&#34;...Hello.....&#34;, both, $.).
&#34;Hello&#34;</PRE></UL>
<P><A NAME="left%2"><STRONG><CODE>left(String, Number) -&#62; Left</CODE></STRONG></A><BR>
<A NAME="left%3"><STRONG><CODE>left(String, Number, Character) -&#62; Left</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = Left = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <CODE>String</CODE> with the length adjusted in
accordance with <CODE>Number</CODE>. The left margin is
fixed. If the <CODE>length(String)</CODE> &#60; <CODE>Number</CODE>,
<CODE>String</CODE> is padded with blanks or <CODE>Character</CODE>s.
<P>For example:<PRE>&#62; string:left(&#34;Hello&#34;,10,$.).
&#34;Hello.....&#34;</PRE></UL>
<P><A NAME="right%2"><STRONG><CODE>right(String, Number) -&#62; Right</CODE></STRONG></A><BR>
<A NAME="right%3"><STRONG><CODE>right(String, Number, Character) -&#62; Right</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = Right = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <CODE>String</CODE> with the length adjusted in
accordance with <CODE>Number</CODE>. The right margin is
fixed. If the length of <CODE>(String)</CODE> &#60; <CODE>Number</CODE>,
<CODE>String</CODE> is padded with blanks or <CODE>Character</CODE>s.
<P>For example:<PRE>&#62; string:right(&#34;Hello&#34;, 10, $.).
&#34;.....Hello&#34;</PRE></UL>
<P><A NAME="centre%2"><STRONG><CODE>centre(String, Number) -&#62; Centered</CODE></STRONG></A><BR>
<A NAME="centre%3"><STRONG><CODE>centre(String, Number, Character) -&#62; Centered</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = Centered = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a string, where <CODE>String</CODE> is centred in the
string and surrounded by blanks or characters. The resulting
string will have the length <CODE>Number</CODE>.
</UL>
<P><A NAME="sub_string%2"><STRONG><CODE>sub_string(String, Start) -&#62; SubString</CODE></STRONG></A><BR>
<A NAME="sub_string%3"><STRONG><CODE>sub_string(String, Start, Stop) -&#62; SubString</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>String = SubString = string()</CODE></STRONG><BR>
<STRONG><CODE>Start = Stop = integer()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a substring of <CODE>String</CODE>, starting at the
position <CODE>Start</CODE> to the end of the string, or to and
including the <CODE>Stop</CODE> position.
<P>For example:<PRE>sub_string(&#34;Hello World&#34;, 4, 8).
&#34;lo Wo&#34;</PRE></UL>
<H3>Notes</H3>
<UL>
<P>Some of the general string functions may seem to overlap each
other. The reason for this is that this string package is the
combination of two earlier packages and all the functions of
both packages have been retained.

<P>The regular expression functions have been moved to their own
module <CODE>regexp</CODE> (see <A HREF="regexp.html">regexp</A>). The old entry points still
exist for backwards compatibility, but will be removed in a
future release so that users are encouraged to use the module
<CODE>regexp</CODE>.

<P><TABLE CELLPADDING=4>
<TR>
      <TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
      <TD>
<P>Any undocumented functions in <CODE>string</CODE> should not be used.
</TD>
</TR>
      </TABLE>
</UL>
<H3>AUTHORS</H3>
<UL>
Robert Virding - support@erlang.ericsson.se<BR>
Torbjorn Tornkvist - support@erlang.ericsson.se<BR>
</UL>
<CENTER>
<HR>
<FONT SIZE=-1>stdlib 1.10<BR>
Copyright &copy; 1991-2001
<A HREF="http://www.erlang.se">Ericsson Utvecklings AB</A><BR>
<!--#include virtual="/ssi/otp_footer.html"-->
</FONT>
</CENTER>
</BODY>
</HTML>