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



The %scan and %replace is easy enough, however, will it eliminate the extra 
spaces?

Example: "THIS, IS. A, TEST. ONLY"

Even using %xlate can give me this in two statements: "THIS  IS  A  TEST  ONLY"

But what I need is this: "THIS IS A TEST ONLY"


-Tracy
 Ext. 3107


-----Original Message-----
From: Scott Klement [mailto:klemscot@klements.com]
Sent: Tuesday, January 14, 2003 6:52 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Removing punctuation (not using arrays)



On Tue, 14 Jan 2003, Tracy Ball wrote:
>
> If I have this field value "RABBIT PACK, 6PC. WINE TOOL KIT", is there a
> better method of removing the comma and period characters and discarding
> the extra spaces created without using an array routine of reading one
> byte at a time, translating the unwanted characters to "blanks" and then
> reloading the field via array positions?

Instead of reading it one byte at a time, you COULD use the %scan BIF
(or SCAN op-code) to find each punctuation character... the down-side to
this is that it has to search the entire string over and over for each
punctuation symbol you want to remove, which could end up being a
performance issue (especially if the string is very large)

Still, if this interests you, try searching the archives for the
%scan and %replace BIFs... I'm sure you'd find an example.

>
> Can I use the %xlate and %trim %bifs to shorten this task?  I don't have
> REXX, so that is not an option.
>

The BIFs that I would use would actually be %subst and %replace.   I would
still loop through every character, and use %replace to remove the
characters that I don't want.

Here's some sample code that illustrates how I'd do it:

     D x               S             10I 0
     D len             S             10I 0
     D string          s            100A

     c                   eval      string = '"RABBIT PACK, 6PC. WINE TOOL KIT"'
     c                   eval      len = %len(%trimr(string))
     c                   eval      x = 1

     c                   dow       x <= len

     c                   if        %subst(string:x:1) = '.'
     c                               or %subst(string:x:1) = ','
     c                               or %subst(string:x:1) = ';'
     c                               or %subst(string:x:1) = '"'
     c                   eval      string = %replace('': string: x: 1)
     c                   else
     c                   eval      x = x + 1
     c                   endif

     c                   enddo

     c                   eval      *inlr = *on


Note that it doesn't advance to the next position unless no %replace
was necessary.  This is because the %replace moved all of the characters
to the left one space, so you'll already be on the next position.

Hope this is helpful.


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



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.