我想在指定的子字符串之前提取字符,这是我到目前为止的
Dim MyStr As variant, Z as variant, Z1 as variant
'the string to extract character from
MyStr="-4<3x-6<12"
'locate the "<" in the string set it as value of Variable Z
Z= InstrRev(MyStr, "<")
If Z then MsgBox "string is" & Mid$
Mid$
代表了我无法弄清楚的一点。
如何返回值6,即<
答案 0 :(得分:2)
简短的回答是InstrRev返回“&lt;”的位置所以你只需要减去1来找到它前面的字符。
我对你的代码有一些评论:
记住这一点我将代码更改为:
Dim MyStr As String
Dim lngZ As Long ', Z1 As String
'the string to extract character from
MyStr = "-4<3x-6<12"
'locate the "<" in the string set it as value of Variable Z
lngZ = InStrRev(MyStr, "<")
If lngZ > 0 Then
MsgBox "string is " & Mid$(MyStr, lngZ - 1, 1)
End If