[erlang-questions] String to proplist

Bengt Kleberg bengt.kleberg@REDACTED
Fri Nov 23 08:22:28 CET 2007


greetings,

a naive version (to get you started :-) is:
proplist_from_options( Options ) ->
	Props = string:tokens( Options, ", " ), % should give you ["abc=12343", 
"someThing=value"]
	Fun = fun (Prop) -> [Name,Value] = string:tokens( Prop, "=" ), 
{erlang:list_to_atom( Name ),Value} end,
	lists:map( Fun, Props ).


expand on this by considering erlang:list_to_existing_atom/1 and if 
Props might contain empty ("") strings, too. Etc, etc


bengt
Those were the days...
    EPO guidelines 1978: "If the contribution to the known art resides
    solely in a computer program then the subject matter is not
    patentable in whatever manner it may be presented in the claims."


On 11/23/07 06:37, Richard Andrews wrote:
> I have a free-form options string that I want to covert to a proplist.
> 
> eg. I want to convert
> 
> "abc=12343, someThing=value" -> [{abc,12343}, {someThing,value}]
> 
> Is there an existing mechanism to perform this conversion?
> If not, what would be the best way to go about it.
> 
> 
> 
> 
>       Make the switch to the world's best email. Get the new Yahoo!7 Mail now. www.yahoo7.com.au/worldsbestemail
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list