string to tupple ?
Tim Fletcher
mail@REDACTED
Mon Jun 21 11:11:28 CEST 2010
> I would like to transform this string in order to easily manipulate each coordinate.
> What is the best representation in erlang ?
> - a list of tupples : if yes how to transform it in [{a,b},{c,d},{e,f}, ....]
If you want tuples then another option would be to use regular
expressions, for example:
String = "(1,2),(3,4)",
{match, Groups} = re:run(String, "\\(([^,]+),([^,]+)\\)", [{capture,
all_but_first, list}, global]),
[{list_to_integer(X), list_to_integer(Y)} || [X, Y] <- Groups].
Also works with floats; just replace the calls to list_to_integer with
list_to_float.
Tim
More information about the erlang-questions
mailing list