Ever wanted to get the names of the images in the current document that are attachments? This short code snippet does it in @Formula:
allowed:="jpg" : "gif" : "png" : "bmp";
attNames:=@LowerCase(@AttachmentNames);
n:=1;
s:="";
@While (n <= @Elements(allowed);
m:=1;
@While(m <= @Elements(attNames);
s:=s : @If(
@RightBack(attNames[m]; ".") = allowed[n]; attNames[m];
""
);
m:=m + 1
);
n:=n + 1
);
@Trim(s)
This tip applies to R6.x, where it's possible to create loops. If anyone has achived the same in R5.x, or have a better alternative to the above, please let me know.
Mattias Kihlström sent me this one-loop-alternative, that looks nicer. A bonus is that the files variable contains all attachment names that are not images.
attNames := @AttachmentNames;
allowed:="gif" : "jpg" : "bmp" : "png" : "jpeg";
@For(i:= 1; i <= @Elements(attNames); i:= i + 1;
extension:= @LowerCase(@RightBack(attNames[i]; "."));
@If(extension = allowed; images:= images : attNames[i]; files:= files : attNames[i])
);
@Trim(images)
A former collegue of mine, Mats Hasselquist, came up with this neat solution that works in R5:
attNames:= @LowerCase(@AttachmentNames);
allowed:= "gif" : "jpg" : "bmp" : "png" : "jpeg";
tmpList:= @Trim(@LeftBack(@ReplaceSubstring(attNames; "." + allowed; "*Dummy*"); "*Dummy*"))
*+ ("." + allowed);
RemoveList:= @Trim(@Replace(tmpList; attNames; ""));
@Trim(@Replace(tmpList; RemoveList; ""));