Good News Everybody!
The new search engine is LIVE!
Please report any problems to david (at) midrange.com.
|
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 mailing list archive is Copyright 1997-2026 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.