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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>string</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
<STYLE TYPE="text/css">
<!--
.REFBODY { margin-left: 13mm }
.REFTYPES { margin-left: 8mm }
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
<IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>string</H1>
</CENTER>
<H3>MODULE</H3>
<DIV CLASS=REFBODY>
string
</DIV>
<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
String Processing Functions
</DIV>
<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>
<P>This module contains functions for string processing.
</DIV>
<H3>EXPORTS</H3>
<P><A NAME="len/1"><STRONG><CODE>len(String) -> Length</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
<STRONG><CODE>Length = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns the number of characters in the string.
</DIV>
<P><A NAME="equal/2"><STRONG><CODE>equal(String1, String2) -> bool()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String1 = String2 = string()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Tests whether two strings are equal. Returns <CODE>true</CODE> if
they are, otherwise <CODE>false</CODE>.
</DIV>
<P><A NAME="concat/2"><STRONG><CODE>concat(String1, String2) -> String3</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String1 = String2 = String3 = string()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Concatenates two strings to form a new string. Returns the
new string.
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
<STRONG><CODE>Index = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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.
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = SubString = string()</CODE></STRONG><BR>
<STRONG><CODE>Index = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = Chars = string()</CODE></STRONG><BR>
<STRONG><CODE>Length = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = SubString = string()</CODE></STRONG><BR>
<STRONG><CODE>Start = Length = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<P><A NAME="tokens/2"><STRONG><CODE>tokens(String, SeparatorList) -> Tokens</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = SeparatorList = string()</CODE></STRONG><BR>
<STRONG><CODE>Tokens = [string()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>.
</DIV>
<P><A NAME="copies/2"><STRONG><CODE>copies(String, Number) -> Copies</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = Copies = string()</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Returns a string containing <CODE>String</CODE> repeated
<CODE>Number</CODE> times.
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
<STRONG><CODE>Count = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = Word = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = Stripped = string()</CODE></STRONG><BR>
<STRONG><CODE>Direction = left | right | both</CODE></STRONG><BR>
<STRONG><CODE>Character = char()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = Left = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = Right = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = Centered = string()</CODE></STRONG><BR>
<STRONG><CODE>Character = char</CODE></STRONG><BR>
<STRONG><CODE>Number = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>.
</DIV>
<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>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = SubString = string()</CODE></STRONG><BR>
<STRONG><CODE>Start = Stop = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<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>
</DIV>
<P><A NAME="to_float/1"><STRONG><CODE>to_float(String) -> {Float,Rest} | {error,Reason} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
<STRONG><CODE>Float = float()</CODE></STRONG><BR>
<STRONG><CODE>Rest = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = no_float | not_a_list</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Argument <CODE>String</CODE> is expected to start with a valid text
represented float (the digits being ASCII values). Remaining characters
in the string after the float are returned in <CODE>Rest</CODE>.
<P>Example:
<PRE>
> {F1,Fs} = string:to_float("1.0-1.0e-1"),
> {F2,[]} = string:to_float(Fs),
> F1+F2.
0.900000
> string:to_float("3/2=1.5").
{error,no_float}
> string:to_float("-1.5eX").
{-1.50000,"eX"}
</PRE>
</DIV>
<P><A NAME="to_integer/1"><STRONG><CODE>to_integer(String) -> {Int,Rest} | {error,Reason} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
<STRONG><CODE>Int = integer()</CODE></STRONG><BR>
<STRONG><CODE>Rest = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = no_integer | not_a_list</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Argument <CODE>String</CODE> is expected to start with a valid text
represented integer (the digits being ASCII values). Remaining characters
in the string after the integer are returned in <CODE>Rest</CODE>.
<P>Example:
<PRE>
> {I1,Is} = string:to_integer("33+22"),
> {I2,[]} = string:to_integer(Is),
> I1-I2.
11
> string:to_integer("0.5").
{0,".5"}
> string:to_integer("x=2").
{error,no_integer}
</PRE>
</DIV>
<H3>Notes</H3>
<DIV CLASS=REFBODY>
<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(3)</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>
</DIV>
<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Robert Virding - support@erlang.ericsson.se<BR>
Torbjorn Tornkvist - support@erlang.ericsson.se<BR>
</DIV>
<CENTER>
<HR>
<SMALL>stdlib 1.14.2<BR>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|