I am using Regina, not ooRexx.
I can program what I want to do (see below), but it seems
inelegant and I wondered if any of you have better solutions.
I have a string which is a filename. Before the final period
there may be one or more numeric characters. I want to capture those
numbers and their location.
I'm pretty sure there will be exactly one period in the
filename, but there might be non-contiguous numerics, which I'll have
to ignore. There will definitely be filenames without these numerics
which I'll have to bypass.
Here is an overview of my proposed solution:
1. REVERSE the string
2. PARSE to split at the first period
3. VERIFY to find the next non-numeric
4. If non-zero, do the necessary arithmetic to find the location in
the original string.
--
Arthur T. - ar23hur "at" pobox "dot" com
Here is a short REXX program that finds the 1st number (decimal digits only) >in a character string, the search stops before the last period (if any) in a >filename.
The REXX code could be condensed, but I left the code to be be broken down
so as to be easier to read and/or modify.
In
Gerard_Schildberger wrote:
Here is a short REXX program that finds the 1st number (decimal digits only) >in a character string, the search stops before the last period (if any) in a >filename.
Thank you. It's more general than I need because I'm looking for
a number that starts immediately after the period (when reversed).
But it's good to have working code to cannibalize so I can avoid some
of the stupid mistakes.
The REXX code could be condensed, but I left the code to be be broken down >so as to be easier to read and/or modify.
I tend not to condense my REXX code. Even when writing for
myself, I follow Martin Golding's advice: "Always code as if the
person who ends up maintaining your code will be a violent psychopath
who knows where you live."
--
Arthur T. - ar23hur "at" pobox "dot" com
Ah. My REXX program (shown previously) finds the first number in the >filename (before the first period), while your code finds the last number.
The modified REXX program to match what your algorithm does is (which has
to contend with an "extra" error condition):
e = verify(rev, 0123456789, , b) - 1 /*find the "end" of the number. */
if e<1 then e= length(rev) /*handle case of just a number. */
num= reverse( substr(rev, b, e-b+1) ) /*extract the number, reverse it*/
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 285 |
Nodes: | 16 (2 / 14) |
Uptime: | 62:02:19 |
Calls: | 6,488 |
Calls today: | 1 |
Files: | 12,096 |
Messages: | 5,274,518 |