I see two ways to do it Ted, using r-index to substring out the filename or entry(n, list, "\") to pull out the nth entry from a "\" delimited list. This code illustrates both ...
def var vcOpt as char no-undo inital "C:\documents\partlist\NewPart1234.pdf".
def var viTemp as int no-undo.
def var vcTemp as char no-undo.
def var vcFID as char no-undo.
assign
viTemp = num-entries(vcOpt, "~\")
vcFID = (if viTemp > 0 then entry(viTemp, vcOpt, "~\") else vcOpt)
vitemp = r-index(vcOpt, "~\").
if viTemp > 0 then do:
vcTemp = substring(vcOpt, viTemp + 1).
end.
return "Given: " + vcopt
+ '~n' + ' R-Index: ' + string(vitemp)
+ '~n' + ' Filename: ' + vctemp
+ '~n' + ' Entry(viTemp, vcOpt): ' + vcFID.
----------- output:
Given: C:\documents\partlist\NewPart1234.pdf
R-Index: 22
Filename: NewPart1234.pdf
Entry(viTemp, vcOpt): NewPart1234.pdf
Personally I like using NUM-ENTRIES( ) and ENTRY( ) when I don't have to deal with a portion of the resulting string. But either method would work.
Note the use of tilde ~\ to take the backslash literally as it is an escape cahracter in certain ABL contexts (just checked this in the ABL Ref and that might only be under Unix. Old habbits die hard!)
- Chris
def var vcOpt as char no-undo inital "C:\documents\partlist\NewPart1234.pdf".
def var viTemp as int no-undo.
def var vcTemp as char no-undo.
def var vcFID as char no-undo.
assign
viTemp = num-entries(vcOpt, "~\")
vcFID = (if viTemp > 0 then entry(viTemp, vcOpt, "~\") else vcOpt)
vitemp = r-index(vcOpt, "~\").
if viTemp > 0 then do:
vcTemp = substring(vcOpt, viTemp + 1).
end.
return "Given: " + vcopt
+ '~n' + ' R-Index: ' + string(vitemp)
+ '~n' + ' Filename: ' + vctemp
+ '~n' + ' Entry(viTemp, vcOpt): ' + vcFID.
----------- output:
Given: C:\documents\partlist\NewPart1234.pdf
R-Index: 22
Filename: NewPart1234.pdf
Entry(viTemp, vcOpt): NewPart1234.pdf
Personally I like using NUM-ENTRIES( ) and ENTRY( ) when I don't have to deal with a portion of the resulting string. But either method would work.
Note the use of tilde ~\ to take the backslash literally as it is an escape cahracter in certain ABL contexts (just checked this in the ABL Ref and that might only be under Unix. Old habbits die hard!)
- Chris
--- In vantage@yahoogroups.com, "tkoch77" <tkoch77@...> wrote:
>
> In need of some 4GL code help. For example, I have a value that is C:\documents\stuff\Document1.docx and another time it could be C:\documents\partlist\NewPart1234.pdf. I want to return Document1.docx and NewPart1234.pdf from the strings. How can I tell it with 4GL code to always trim after the last "\"?
>
> Thanks for any help,
> Ted
>