我目前正在尝试制作一个应用程序,它将替换两个字符串之间的值,但我使用的代码不起作用,任何人都知道如何正确执行此操作?vb.net查找两个字符串之间的字符串
Dim sSource As String = "64616D616765002D3100" 'String that is being searched
Dim sDelimStart As String = "64616D61676500" 'First delimiting word
Dim sDelimEnd As String = "00" 'Second delimiting word
Dim nIndexStart As Integer = sSource.IndexOf(sDelimStart) 'Find the first occurrence of f1
Dim nIndexEnd As Integer = sSource.IndexOf(sDelimEnd) 'Find the first occurrence of f2
If nIndexStart > -1 AndAlso nIndexEnd > -1 Then '-1 means the word was not found.
Dim res As String = Strings.Mid(sSource, nIndexStart + sDelimStart.Length + 1, nIndexEnd - nIndexStart - sDelimStart.Length) 'Crop the text between
MessageBox.Show(res) 'Display
Else
MessageBox.Show("One or both of the delimiting words were not found!")
End If
这是我得到的方式错误“类型‘System.ArgumentException’未处理的异常发生在Microsoft.VisualBasic.dll中 其他信息:参数‘长度’必须大于或等于零“。 –
我假设这个错误是? nIndexEnd - nIndexStart - sDelimStart.Length? 为什么你不能使用替换功能? – Pure
是的,因为我想要替换的值总是不同,但前后的字符串总是相同的,所以我需要找到值并替换 –