|
On Tue, 5 Feb 2002 Peter_Vidal@pall.com wrote:
>
> For example, I have a link like this:
> NPR-SERVER-NT/SCANNING/Common/Steve%20Maher/EAR90881/AC9012F1240Y6.B.HPGL
>
> I need to just get the file name only. However, I am trying to use the CHECKR
I realize that you've already solved this... (it's a pretty common
thing to need to do, so I imagine many people have or will give you
solutions)
But, here's a slightly more efficient method. Rather than scanning the
string several times to find all the slashes, it uses the C "strrchr"
function which scans for a single character, starting at the end of
the string... since it only scans the string once, it'll run slightly
faster...
H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('QC2LE')
D basename PR 256A
D path 256A const
D my_file S 50A
D my_path S 256A
c eval my_path = '/NPR-SERVER-NT/SCANNING/' +
c 'Common/Steve%20Maher/' +
c 'EAR90881/AC9012F1240Y6.B.HPGL'
c eval my_file = basename(my_path)
c dsply my_file
c eval *inlr = *on
P basename B
D basename PI 256A
D path 256A const
d strrchr PR * extproc('strrchr')
d wholestr * value options(*string)
d char 10I 0 value
D SLASH c const(97)
D p S *
c eval p = strrchr(path: SLASH)
c if p = *NULL
c return *blanks
c else
c eval p = p + 1
c return %str(p)
c endif
P E
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.