Category:StringRecipes
From Erlang Community
| Revision as of 22:03, 3 September 2006 (edit) Bfulgham (Talk | contribs) ← Previous diff |
Current revision (13:20, 25 July 2007) (edit) (undo) Rk (Talk | contribs) (→References - Fixed broken links.) |
||
| (4 intermediate revisions not shown.) | |||
| Line 1: | Line 1: | ||
| + | == Introduction == | ||
| + | In Erlang, a string is a list of characters. The designers of Erlang thoughtfully included a bit of syntactic sugar so that strings in source code could be easily read. A string is written by enclosing the characters with a doublequote ("). Some special characters must be preceded by a backslash, these include doublequote and backslash. The technique of marking special characters is called escaping and backslash itself is called an escape character. | ||
| + | |||
| + | Examples of literal strings: | ||
| + | <code> | ||
| + | "Hello world" | ||
| + | "This string has a \" in it" | ||
| + | "This character \\ is a slash" | ||
| + | </code> | ||
| + | |||
| + | Since Erlang stores its strings as lists of characters, writing the string "Hello world." like this: | ||
| + | <code> | ||
| + | A = "Hello world.". | ||
| + | "Hello world." | ||
| + | </code> | ||
| + | |||
| + | is exactly the same (to Erlang) as writing this: | ||
| + | <code> | ||
| + | A = [72,101,108,108,111,32,119,111,114,108,100,46]. | ||
| + | "Hello world." | ||
| + | </code> | ||
| + | |||
| + | which is exactly the same as writing this: | ||
| + | <code> | ||
| + | A = [$H, $e, $l, $l, $o, $\s, $w, $o, $r, $l, $d, $.]. | ||
| + | "Hello world." | ||
| + | </code> | ||
| + | |||
| + | In Erlang, strings are lists of characters (really, lists of integers). Since you can't talk about strings without talking about characters, you should know that Erlang supports the Basic Latin and Latin-1 Supplement, a.k.a. ISO-8859-1. | ||
| + | |||
| + | You can specify a character with the sequence $ followed by the character, i.e. | ||
| + | <code> | ||
| + | 1> $A. | ||
| + | 65 | ||
| + | 2> $a. | ||
| + | 97 | ||
| + | 3> $*. | ||
| + | 42 | ||
| + | </code> | ||
| + | |||
| + | Since Erlang stores all strings as a sequence of integers, it actually supports all of the Unicode character sets, since they simply map into a set of numbers. Unfortunately, Erlang does not currently support reading native unicode files or sorting in locale-specific ways based on unicode. However, there are plans to do this in the future. | ||
| + | |||
| + | == References == | ||
| + | The following pages in the [http://www.erlang.org/doc/ Erlang Documentation] may be helpful in your string efforts: | ||
| + | * [http://www.erlang.org/doc/reference_manual/data_types.html#2.11 String Section of the Erlang Reference Manual (Sect 2.11)] | ||
| + | * [http://www.erlang.org/doc/man/lists.html List Libraries ] | ||
| + | * [http://www.erlang.org/doc/man/string.html String Libraries] | ||
| + | * [http://www.erlang.org/doc/man/io_lib.html Basic I/O Libraries] | ||
| + | |||
| [[Category:CookBook]] | [[Category:CookBook]] | ||
Current revision
[edit] Introduction
In Erlang, a string is a list of characters. The designers of Erlang thoughtfully included a bit of syntactic sugar so that strings in source code could be easily read. A string is written by enclosing the characters with a doublequote ("). Some special characters must be preceded by a backslash, these include doublequote and backslash. The technique of marking special characters is called escaping and backslash itself is called an escape character.
Examples of literal strings:
"Hello world" "This string has a \" in it" "This character \\ is a slash" |
Since Erlang stores its strings as lists of characters, writing the string "Hello world." like this:
A = "Hello world.". "Hello world." |
is exactly the same (to Erlang) as writing this:
A = [72,101,108,108,111,32,119,111,114,108,100,46]. "Hello world." |
which is exactly the same as writing this:
A = [$H, $e, $l, $l, $o, $\s, $w, $o, $r, $l, $d, $.]. "Hello world." |
In Erlang, strings are lists of characters (really, lists of integers). Since you can't talk about strings without talking about characters, you should know that Erlang supports the Basic Latin and Latin-1 Supplement, a.k.a. ISO-8859-1.
You can specify a character with the sequence $ followed by the character, i.e.
1> $A. 65 2> $a. 97 3> $*. 42 |
Since Erlang stores all strings as a sequence of integers, it actually supports all of the Unicode character sets, since they simply map into a set of numbers. Unfortunately, Erlang does not currently support reading native unicode files or sorting in locale-specific ways based on unicode. However, there are plans to do this in the future.
[edit] References
The following pages in the Erlang Documentation may be helpful in your string efforts:
- String Section of the Erlang Reference Manual (Sect 2.11)
- List Libraries
- String Libraries
- Basic I/O Libraries
Articles in category "StringRecipes"
There are 28 articles in this category.
ACDFPS |
S cont. |
S cont.
T |

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

