将一个字符串的字符串删除到 vb.net 的末尾
Deleting string of a string to its end in vb.net
如果我有这个:
Dim str as String = "This is a string to delete"
我使用contain方法检测str
里面的"String"如果发现"String"也会删除str的最后一个字符的下一个字符。
str = "This is a "
删除字符串最后一部分的一种方法是使用 IndexOf
找到要删除的部分的位置,然后 Substring
将其删除
Dim str As String = "This is a string to delete"
Dim loc As Integer = str.IndexOf("string")
If loc >= 0 Then str = str.Substring(0, loc)
听起来您想要删除指定的字符串,以及该字符串后面的第一个字符。如果那是正确的,可以这样做:
Dim str As String = "This is a string to delete"
Dim stringToRemove As String = "string"
str = str.Replace(str.Substring(InStr(str, stringToRemove) - 1, stringToRemove.Length + 1), "")
如果我有这个:
Dim str as String = "This is a string to delete"
我使用contain方法检测str
里面的"String"如果发现"String"也会删除str的最后一个字符的下一个字符。
str = "This is a "
删除字符串最后一部分的一种方法是使用 IndexOf
找到要删除的部分的位置,然后 Substring
将其删除
Dim str As String = "This is a string to delete"
Dim loc As Integer = str.IndexOf("string")
If loc >= 0 Then str = str.Substring(0, loc)
听起来您想要删除指定的字符串,以及该字符串后面的第一个字符。如果那是正确的,可以这样做:
Dim str As String = "This is a string to delete"
Dim stringToRemove As String = "string"
str = str.Replace(str.Substring(InStr(str, stringToRemove) - 1, stringToRemove.Length + 1), "")