× 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 Fri, Feb 22, 2013 at 1:24 PM, DeLong, Eric <EDeLong@xxxxxxxxxxxxxxx> wrote:
Hmm, just an observation...

I think the NORMAL pattern of use in the case where
you're concatenating a bunch of [fixed-length] fields together is:

myString += %trim( theSalutation ) + ' ' +
%trim( theFirstName ) + ' ' +
%trim( theLastName );

Even this would have issues if theSalutation was blank... The
correction for that is another %trim, unfortunately...

myString += %trim( %trim( theSalutation ) + ' ' +
%trim( theFirstName ) + ' ' +
%trim( theLastName ) );

We NEVER want to ASSUME that blanks in data fields will be consistent...

Well, to take it a step further, there is also the problem of what
happens if the first name is blank but the salutation is not. Then
you'll have two spaces between "Mr" and "Hamberg".

So if you really want to get it right in RPG, you have use a series of
IFs (checking each component to see if it's empty) or use a loop at
the end with a second string variable to use as a workspace. (The
latter is well-suited to being put in a procedure, especially a
procedure in a service program.)

If you must use RPG, it's totally worth it to set up some reusable
advanced string functions. But if you don't already have these, it
may be easier to just use a language that was designed with
string-handling in mind. Example in Python:

pieces = (theSalutation, theFirstName, theLastName)
myString = ' '.join(' '.join(pieces).split())

Finally, it's worth noting that if you are building strings containing
HTML meant to be read by a browser, then extra spaces are actually
fine anyway (the browser automatically reduces multiple adjacent
spaces to a single space). It's when you want to force extra spaces
where things get tricky (or more annoying)!

John

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.