× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Yup - I’ve already modified to to handle spaces John. Made a few other changes as well and will post the modified version back to Midrange code once I’m done with it.

I thought about Regex but I want this thing to work for mere mortals - not just the small subset who understand regex <grin>

If I’m being 100% honest I should also say that although I have a basic knowledge of regex I am not in the “understand” category - I’m more in the google until you find roughly the pattern you want and then bully it into submission. Doesn’t hep of course that there is no one standard regex!


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On May 24, 2016, at 1:37 PM, John Yeung <gallium.arsenide@xxxxxxxxx> wrote:

On Tue, May 24, 2016 at 12:35 PM, Jon Paris <jon.paris@xxxxxxxxxxxxxx> wrote:
Looks like Steve’s subproc is the best starting point.

Very good starting point indeed! I think it puts you on the finish
line, or at most a few inches off it. I guess the thing that it
doesn't handle is having an actual space in your desired mask, such as
in your example of transforming 'ABCDEFGHI' into 'AB-CD-EFGH I'. So
instead of using a space as the "fill placeholder", you have to pick
something that can't show up in your mask.

Just because I tend toward the academic, I'll note that I thought of
something in other languages (and possibly available to RPG through
APIs or what have you) that would work pretty well for this: regular
expression substitution.

In Python, for example, the aforementioned 'ABCDEFGHI' -> 'AB-CD-EFGH
I' could be accomplished (interactively) like this:

import re
print re.sub(r'(..)(..)(....)(.)', r'\1-\2-\3 \4', 'ABCDEFGHI')

Or, a function that accepts an input string and returns the reformatted string:

import re
def edit(s):
return re.sub(r'(..)(..)(....)(.)', r'\1-\2-\3 \4', s)

It should be similar in any language that has what I'll call
"Perl-inspired" regular expressions. (This would include Java, Ruby,
PHP, JavaScript, and many others.) You could of course also pass the
match pattern and substitution pattern as parameters instead of making
them literals.

For this level of code conciseness, you'd have to convert your "edit
masks" to regex patterns. If that's not acceptable, and you have to
work directly with the edit masks, then I think you pretty much wind
up writing Steve's routine one way or another.

John Y.
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.