× 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.



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.

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.