检查字符串是否以vbcrlf开头或结尾
问题描述:
如何检查字符串是否以vbcrlf
开头(或结尾)?检查字符串是否以vbcrlf开头或结尾
我tryed与substring
但它不似乎工作:
Dim s As String = ""
s &= vbCrLf & "Test"
If s.Substring(0, 1) = vbCrLf Then
MsgBox("Yes")
End If
答
试试这个
StartsWith - 检查字符串的第一部分。
Dim s As String = "vbCrLf bla bla bla"
If s.StartsWith("vbCrLf") Then
MsgBox("Yes")
End If
的endsWith - 检查字符串的最后一个字符。
Dim s As String = "bla bla bla vbCrLf"
If s.EndsWith("vbCrLf") Then
MsgBox("Yes")
End If
请注意,这是默认情况下使用文化相关的字符串比较。例如,在我所知道的所有文化中,“Strassenbahn”.StartWith(“Straße”)将是“True”。还有'StartsWith'和'EndsWith'的其他重载,您可以在其中指定___根据_比较,或者指定与文化相关的比较,但使用'InvariantCulture'。 –
请注意OP代码不起作用的原因是vbcrlf是_two_个字符。 '如果s.Substring(0,2)= vbCrLf'按预期工作。 – peterG