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

/ Erlang.StringRecipeConversionStringVsAtom

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

Converting Between Strings and Atoms

Problem

You want to convert an atom to a string or vice versa

Solution

The built-in function list_to_atom converts from a string to an atom, and atom_to_list does the conversion in the other direction.

For example:

1> list_to_atom("hello").
hello
2> atom_to_list(hello).
"hello"

Discussion

Note that by default Erlang is case sensitive, so the atom hello, Hello and HeLLo are unique:

1> hello = hEllo.
** exited: {{badmatch,hEllo},[{erl_eval,expr,3}]} **
2> hello = hello.
hello

-- BrentAFulgham - 20 Aug 2004

CookbookForm
TopicType: Recipe
ParentTopic: StringRecipes
TopicOrder: 040

 
 
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