Last active
June 14, 2020 23:33
-
-
Save CarlTBarnes/45e9e2f25ac304e44451a5558490e36d to your computer and use it in GitHub Desktop.
Find the File .EXT on the end of a File Name after last period
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAP | |
FileExtension PROCEDURE(*STRING FN),STRING | |
MODULE('RTL') | |
LenFastClip PROCEDURE(CONST *STRING Text2Measure),LONG,NAME('Cla$FASTCLIP') | |
END | |
END | |
!-------------------------------------- | |
FileExtension PROCEDURE(*STRING FN)!,STRING | |
L USHORT,AUTO | |
Ext STRING(24),AUTO | |
CODE | |
L=INSTRING('.',FN,-1,SIZE(FN)) !Last Period | |
IF L THEN | |
Ext=SUB(FN,L+1,24) | |
! L=LEN(CLIP(Ext)) | |
L=LenFastClip(Ext) | |
IF L<=3 AND L THEN | |
RETURN UPPER(Ext[1 : L]) ! 3 Char .Ext .EXT | |
ELSIF L THEN !Period alone should not happen | |
Ext[1]=UPPER(Ext[1]) ! Upper letter 1 | |
RETURN Ext[1 : L] | |
END | |
END | |
RETURN '' | |
!-------------------------------------- | |
! Less Code - returns 1 blank if the impossible happens, a file with '.' and no EXT | |
!-------------------------------------- | |
FileExtension PROCEDURE(*STRING FN)!,STRING | |
L USHORT,AUTO | |
Ext STRING(24),AUTO | |
CODE | |
L=INSTRING('.',FN,-1,SIZE(FN)) | |
IF ~L THEN RETURN ''. | |
Ext=SUB(FN,L+1,24) | |
! L=LEN(CLIP(Ext)) | |
L=LenFastClip(Ext) | |
IF L<=3 AND L THEN RETURN UPPER(Ext[1 : L]). ! 3 Char UPPER | |
IF ~L THEN L=1. ! Period alone should never happen, if it does let's not GPF | |
Ext[1]=UPPER(Ext[1]) ! Upper letter 1 | |
RETURN Ext[1 : L] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment