Tim*_*ams 29
短:
Split(stringval,":")(0)
Run Code Online (Sandbox Code Playgroud)
Ste*_*ory 11
首先测试':',然后将测试字符串调到':'或结束,具体取决于是否找到它
Dim strResult As String
' Position of :
intPos = InStr(1, strTest, ":")
If intPos > 0 Then
' : found, so take up to :
strResult = Left(strTest, intPos - 1)
Else
' : not found, so take whole string
strResult = strTest
End If
Run Code Online (Sandbox Code Playgroud)
在这种情况下,你可以先找到字符串的位置":"
'position = InStr(StringToSearch, StringToFind)
position = InStr(StringToSearch, ":")
Run Code Online (Sandbox Code Playgroud)
然后使用Left(StringToCut,NumberOfCharacterToCut)
Result = Left(StringToSearch, position -1)
Run Code Online (Sandbox Code Playgroud)