e r l a n g : c o o k b o o k

/ Erlang.StringIntroduction

This Web


WebHome 
WebChanges 
TOC
NewRecipe 
WebTopicList 
WebStatistics 

All Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Erlang Links


Erlang.org
Erlang Wiki
ErlMan
Erlang Wiki
The Jungerl
Erlang-fr.org
Joe Armstrong
Lambda the Ultimate

Erlang Web Ring


[Prev]: Joe Armstrong's Page
[Next]: Joe Armstrong's Page

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, $ , $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.

CookbookForm
TopicType: Section
ParentTopic: StringChapter
TopicOrder: 010

 
 
Copyright © 2004 by the contributing authors. All material on the Erlang Cookbook web site is the property of the contributing authors.
This material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest