gpt4 book ai didi

arrays - 如何在 MS Access 中过滤掉数组的空元素

转载 作者:行者123 更新时间:2023-12-04 07:11:12 26 4
gpt4 key购买 nike

我正在从其他一些字段中生成标题,并希望以“正确”的方式来做:

Me.Title.Value = Join(Array([Conference], [Speaker], partstr), " - ")

除了 [conference]、[speaker] 或 partstr 中的任何一个可能为空,我不想要额外的“-”。是否有任何功能可以使这项工作变得简单明了?

最佳答案

不 - 你必须检查每一个,然后在最后清理

Dim Temp As String

If Not IsNull([Conference]) Then
Temp = Temp & [Conference] & " - "
End If

If Not IsNull([Speaker]) Then
Temp = Temp & [Speaker] & " - "
End If

If Not IsNull(partstr) Then
Temp = Temp & partstr & " - "
End If

If Temp > "" then
Me.Title.Value = Left(Temp, Len(Temp) - 3)
Else
Me.Title.Value = Null
End If

修改为通用功能:
Public Function JoinEx(ByVal pArray As Variant, ByVal pDelimiter As String) As String

Dim sTemp As String
Dim iCtr As Integer

For iCtr = 0 To UBound(pArray)
If Not IsNull(pArray(iCtr)) Then
sTemp = sTemp & pArray(iCtr) & pDelimiter
End If
Next

If sTemp > "" Then
JoinEx = Left(sTemp, Len(sTemp) - Len(pDelimiter))
End If

End Function

调用示例:
 JoinEx(Array("one","two","three"), " - ")  'Returns "One - Two - Three"
JoinEx(Array(null,"two","three"), " - ") 'Returns "Two - Three"

关于arrays - 如何在 MS Access 中过滤掉数组的空元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/318198/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com