【发布时间】:2015-04-17 22:11:43
【问题描述】:
我只想选择在括号“()”之间找到的字符我找到了可以在同一字符串之间选择字符的代码:
Public Function GetStuffYouWant(ByVal pInput As Variant, _
Optional pSplitChar As String = "-") As Variant
Dim varResult As Variant
Dim varPieces As Variant
If IsNull(pInput) Then
varResult = Null
Else
varPieces = Split(pInput, pSplitChar)
If UBound(varPieces) > 1 Then
varResult = varPieces(1)
Else
varResult = Null
End If
End If
GetStuffYouWant = varResult
End Function
效果很好,因为当有空值时,我不会收到空错误。
问题是我需要在两个已知字符串之间选择字符。我发现这段代码查看了两个字符串,但我不知道如何将其写入第一个代码以获得我想要的结果:
dim first as integer
dim second as integer
dim result as string
first = instr(1,"yourtext","-")
second = instr(first+1,"yourtext","-")
if first > 0 and second > first then
second = second - first
result = mid("yourtext",first+1, second-1)
end if
这是我需要的一个例子:
Before: I need:
Issue Issue
------ ------
1 (Dog) at the carpet Dog at the carpet
2 <---Not a null error
3 (Cat) dog Cat
【问题讨论】:
-
您要的是 SQL 还是 VB.net?
-
好问题。我会接受任何将 () 与文本分开而不给我空错误的解决方案。
标签: sql vba ms-access ms-access-2013 jet