Asp.net 如何在VB.NET中从字符串中检索属性作为子字符串

Asp.net 如何在VB.NET中从字符串中检索属性作为子字符串,asp.net,vb.net,Asp.net,Vb.net,我在VB.NET中将值保存为字符串变量。我需要获取值“Stop1”并将其保存在字符串变量中。我应该应用什么逻辑/函数从字符串中提取“Stop1” 这将提取与值相关的全部数据: 它假定您有一个名为s的字符串,其中包含您的数据 'define the string id to find Dim idToFind As String = "value=" 'find it in the string Dim valuePos As Integer = s.IndexOf(idToFind) 'e

我在VB.NET中将
值保存为字符串变量。我需要获取值“Stop1”并将其保存在字符串变量中。我应该应用什么逻辑/函数从字符串中提取“Stop1”

这将提取与
值相关的全部数据

它假定您有一个名为
s
的字符串,其中包含您的数据

'define the string id to find   
Dim idToFind As String = "value="
'find it in the string
Dim valuePos As Integer = s.IndexOf(idToFind)
'extract the part we want
Dim valueString = s.Substring(valuePos + idToFind.Length, s.IndexOf(Chr(34), valuePos) - valuePos + 1)
Dim valueStringNoQuotes = s.Substring(valuePos + idToFind.Length + 1, s.IndexOf(Chr(34), valuePos) - valuePos - 1)
Debug.WriteLine(valueString) 'Output: "Stop1"
Debug.WriteLine(valueStringNoQuotes) 'Output Stop1

如果您计划使用此方法,那么您应该考虑添加一些错误检查,以确保字符串实际包含您期望的数据,检查大写/小写等

为什么需要这样的逻辑?我的str=和我需要获取子字符串“stop1”并将其保存在一个新的字符串变量中。这样我就可以只保存数据库中的“值”。这将始终是“Stop1”还是值中会有其他数据?可以有任何值,而不仅仅是“Stop1”Tim,你是对的!首先,我的逻辑是错误的。我将尝试获取输入框的值,而不是将整个输入框保存在字符串中。我已经使用了您的第一个答案,效果很好!非常感谢