forum-msg-id-132666-edit
Original date:2018-05-24 14:51:09 Edited by: jpartridge Subject: A function that expands value() and more
Hi, It seems that I was finally approved to post on this forum - although I haven't received any confirmation e-mail.
I thought of using Euphoria on a new project due to its (claimed) capacity to easily translate to C.
However, without help and support it may take too long to learn and evaluate its adequacy.
I like to share when I'm learning. I came across a text that states the limitations of the value() built-in function.
I thought it would not be too much difficult to improve it in order to get numbers from strings independently of their position.
Here's what I could do as a beginner (pelease, do feel free to make corrections):
include get.e function val(object parm) -- Gets any numerical value at any position on a string sequence num_val = {} if sequence(parm) then for i = 1 to length(parm) do if parm[i] >= 48 and parm[i] <= 57 then num_val = append(num_val, parm[i]) end if end for num_val = value(num_val) return num_val[2] else return 0 end if end function --tests: print(1, val("This string includes the number 42.")) puts(1, "\n") print(1, val("This string doe not include any number.")) puts(1, "\n") print(1, val("We can extract number 42 from this string and add two.") + 2)
I also wanted to ask an Euphorian that may have the requested reputation to create an Euphoria tag and leave some answer here:
(I'm using ed with a file myshell and the only thing missing is the > before the prompt... while writing the ex files on wee.)
Not Categorized, Please Help
|
- history, backlinks
- Last modified May 24, 2018 by jpartridge