On Mon, Aug 15, 2016 at 4:32 PM, Bradley Stone <bvstone@xxxxxxxxx> wrote:
in your case I would first convert all \ to /

Well, he's already got forward (non-Windows) slashes. (Oh, fun fact:
In many contexts, Windows actually can handle forward slashes.)

then scan for the last /. Then everything after
that is the name and before it is the path.

I think that is the point of his question. He's asking for a nice way
to do that, because he suspects that his current way (which he hasn't
shared with us) is probably not the best way.

This question arises mainly because RPG doesn't have a
"scan-from-right" BIF or opcode. Now, if SQL has something handy, then
by all means, use that (Booth mentioned it will be SQLRPGLE.) But if
SQL is no better than RPG (I don't know if it is), or you are not
using embedded SQL for whatever reason, then the main choices would
seem to be

(1) Do a character-by-character loop yourself, starting from the right.

(2) Use %SCAN repeatedly in a loop until you stop finding more slashes.

(3) Use the SCAN opcode to find multiple slashes, and pick the
rightmost one (assumes your result array has enough slots to
accommodate all the slashes that can be in your input; otherwise you
might as well do option (2)).

Since any kind of loop will be approximately equally clunky, I would
personally pick option (1), which to me is the most straightforward
and dead-simple to understand. It seems the lowest level, but when you
actually code it in RPG, I think it turns out to read the nicest.
Regardless of what you do, you may want to wrap it up and put it in a
service program and try to remember to reuse it.

I cannot stress enough that if SQL has something nicer, just use that.

John Y.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.