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) -> 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) -> 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) -> 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) -> Index</CODE></STRONG></A><BR>
<A NAME="rchr%2"><STRONG><CODE>rchr(String, Character) -> 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) -> Index</CODE></STRONG></A><BR>
<A NAME="rstr%2"><STRONG><CODE>rstr(String, SubString) -> 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>> string:str(" Hello Hello World World ", "Hello World").
8</PRE></UL>
<P><A NAME="span%2"><STRONG><CODE>span(String, Chars) -> Length </CODE></STRONG></A><BR>
<A NAME="cspan%2"><STRONG><CODE>cspan(String, Chars) -> 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>> string:span("\t abcdef", " \t").
5
> string:cspan("\t abcdef", " \t").
0</PRE></UL>
<P><A NAME="substr%2"><STRONG><CODE>substr(String, Start) -> SubString</CODE></STRONG></A><BR>
<A NAME="substr%3"><STRONG><CODE>substr(String, Start, Length) -> 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>> substr("Hello World", 4, 5).
"lo Wo"</PRE></UL>
<P><A NAME="tokens%2"><STRONG><CODE>tokens(String, SeparatorList) -> 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>> tokens("abc defxxghix jkl", "x ").
["abc", "def", "ghi", "jkl"]</PRE></UL>
<P><A NAME="chars%2"><STRONG><CODE>chars(Character, Number) -> String</CODE></STRONG></A><BR>
<A NAME="chars%3"><STRONG><CODE>chars(Character, Number, Tail) -> 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) -> 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) -> Count</CODE></STRONG></A><BR>
<A NAME="words%2"><STRONG><CODE>words(String, Character) -> 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>> words(" Hello old boy!", $o).
4</PRE></UL>
<P><A NAME="sub_word%2"><STRONG><CODE>sub_word(String, Number) -> Word</CODE></STRONG></A><BR>
<A NAME="sub_word%3"><STRONG><CODE>sub_word(String, Number, Character) -> 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>> string:sub_word(" Hello old boy !",3,$o).
"ld b"</PRE></UL>
<P><A NAME="strip%1"><STRONG><CODE>strip(String) -> Stripped</CODE></STRONG></A><BR>
<A NAME="strip%2"><STRONG><CODE>strip(String, Direction) -> Stripped</CODE></STRONG></A><BR>
<A NAME="strip%3"><STRONG><CODE>strip(String, Direction, Character) -> 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>> string:strip("...Hello.....", both, $.).
"Hello"</PRE></UL>
<P><A NAME="left%2"><STRONG><CODE>left(String, Number) -> Left</CODE></STRONG></A><BR>
<A NAME="left%3"><STRONG><CODE>left(String, Number, Character) -> 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> < <CODE>Number</CODE>,
<CODE>String</CODE> is padded with blanks or <CODE>Character</CODE>s.
<P>For example:<PRE>> string:left("Hello",10,$.).
"Hello....."</PRE></UL>
<P><A NAME="right%2"><STRONG><CODE>right(String, Number) -> Right</CODE></STRONG></A><BR>
<A NAME="right%3"><STRONG><CODE>right(String, Number, Character) -> 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> < <CODE>Number</CODE>,
<CODE>String</CODE> is padded with blanks or <CODE>Character</CODE>s.
<P>For example:<PRE>> string:right("Hello", 10, $.).
".....Hello"</PRE></UL>
<P><A NAME="centre%2"><STRONG><CODE>centre(String, Number) -> Centered</CODE></STRONG></A><BR>
<A NAME="centre%3"><STRONG><CODE>centre(String, Number, Character) -> 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) -> SubString</CODE></STRONG></A><BR>
<A NAME="sub_string%3"><STRONG><CODE>sub_string(String, Start, Stop) -> 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("Hello World", 4, 8).
"lo Wo"</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 © 1991-2001
<A HREF="http://www.erlang.se">Ericsson Utvecklings AB</A><BR>
<!--#include virtual="/ssi/otp_footer.html"-->
</FONT>
</CENTER>
</BODY>
</HTML>
|