From: "Richard O'Keefe" <o...@cs.otago.ac.nz>
Date: Thu, 15 Nov 2012 11:04:13 +1300
Local: Wed, Nov 14 2012 5:04 pm
Subject: Re: [erlang-questions] Date Conversion
On 14/11/2012, at 10:26 PM, Lucky Khoza wrote:
> Hi Erlang Developers,
(1) There is no trailing zero there.
> How do i convert date string: "2012/02/15" to 2012/2/15, just to get rid of trailing Zero.
(2) Date standards like ISO 8601 often *require* the leading zero. (3) {ok,[Y,M,D],[]} = io_lib:fread("~d/~d/~d", "2012/02/15"), lists:flatten(io_lib:fwrite("~w/~w/~w", [Y,M,D])) If you just want to write the result, you can use io:fwrite/[2,3] instead of io_lib:fwrite/2. In one sense, Erlang resembles C: formatted input and formatted
Or you could think in terms of a finite state automaton
strip_leading_zeros([$0|Cs]) ->
after_leading_zeros([D|Cs]) when D =< $9, D >= $0 ->
Basically, in a block of digits, leading zeros are removed,
The version with the finite state automaton is almost
_______________________________________________
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||