I have this variable Code in erlang which has this value "T00059"
I want to extract this value 59
from Code.
I try to extract with this code this value "00059"
.
NewCode = string:substr(Code, 2, length(Code)),
Now I want to know how can we eliminate the first zero before the first integer not null. I mean how can we extract "59"
?
For example if I have this value "Z00887"
I should have in the final this value 887
.
You can simply do (output from an interactive erl
session):
1> Code = "Z00887",
1> {NewCode, _Rest} = string:to_integer(string:substr(Code, 2, length(Code))),
1> NewCode.
887
(My answer in test with loop in erlang goes into more detail regarding the same problem)
This code will skip starting zeros. If you want to save them change $1
to $0
extract_integer([]) -> [];
extract_integer([H|T]) when (H >= $1) and (H =< $9) -> [H] ++ T;
extract_integer([_H|T]) -> extract_integer(T).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With