[erlang-questions] How to split such a string elegantly ?
z_axis
z_axis@REDACTED
Mon Jun 20 08:08:18 CEST 2011
The string contains two parts separated by "-", such as "red - blue" .
However, sometimes there may be no red or blue part. For example, the
following are all right string.
"1 2 3 - 33 23", "- 33 23", "1 2 3 -", etc.
>[NoRed,NoBlue] = string:tokens("1 2 3 - 33 23","-").
["1 2 3 "," 33 23"]
>[NoRed,NoBlue] = string:tokens("- 33 23","-"). % i hope it returns ["","
33 23"]
** exception error: no match of right hand side value [" 33 23"]
>[NoRed,NoBlue] = string:tokens("1 2 3 -","-"). % i hope it returns [1 2 3
", ""]
** exception error: no match of right hand side value ["1 2 3 "]
Sincerely!
-----
e^(π.i) + 1 = 0
--
View this message in context: http://erlang.2086793.n4.nabble.com/How-to-split-such-a-string-elegantly-tp3610585p3610585.html
Sent from the Erlang Questions mailing list archive at Nabble.com.
More information about the erlang-questions
mailing list