首页 > 解决方案 > 如何使用 forall 循环将 Lotus 脚本中的字符串与 (##) 连接起来?

问题描述

我想用forall循环连接一个具有多个值的字符串,这里是代码:

varAttachmentNames = Evaluate( "@AttachmentNames" , doc )
Forall strAttachmentName in varAttachmentNames
    Set object = doc.GetAttachment( strAttachmentName )
    fileName = object.Name
End Forall

在循环结束时,如果有多个文件我想要名称为 abc.pdf##xyz.pdf 两者都是文件名中的单独文件名 abc 和 xyz(字符串变量)

标签: lotus-noteslotusscriptdomino-designer-eclipse

解决方案


有很多可能性,有些甚至不需要 LotusScript-Loop:

首先:已经在公式中进行连接:

Dim strResult as String
varAttachmentNames = Evaluate( {@Implode( @AttachmentNames , "##")} , doc )
strResult = varAttachmentNames(0)

第二:在 LotusScript 中使用 @Implode- 对应项:

Dim strResult as String
varAttachmentNames = Evaluate( "@AttachmentNames" , doc )
strResult = Implode( varAttachmentNames, "##" )
' or with the (in other programming languages) more common alias "Join": 
'strResult = Join( varAttachmentNames, "##" )

第三:使用你的 Forall-Loop:

Dim strResult as String
varAttachmentNames = Evaluate( "@AttachmentNames" , doc )
Forall strAttachmentName in varAttachmentNames
    Set object = doc.GetAttachment( strAttachmentName )
    fileName = object.Name
    If strResult = "" then
        strResult = fileName
    Else
        strResult = strResult & "##" & fileName
    End If
End Forall

推荐阅读