基本上,我只是希望能够从一个特定的字符串开始复制到另一个字符串。所以不管介于两者之间的是什么,我希望它能够被复制到剪贴板。我尝试了很多不同的操作,但我无法在任何地方找到答案。请有人帮忙吗?
答案 0 :(得分:0)
如果它是一个数字,你可以循环所有的字符,并将每个字符解析为一个整数,然后任何可以添加到另一个字符串变量,然后解析成一个整数。
Dim string_thathasvalue As String = "</skillAT>49000</skillAT>"
Dim intvalue As Integer
Dim sb As New StringBuilder
For i = 0 To string_thathasvalue.Count - 1
If Integer.TryParse(string_thathasvalue.Substring(i, 1), intvalue) Then
sb.Append(string_thathasvalue.Substring(i, 1))
End If
Next
intvalue = Integer.Parse(sb.ToString)
或者如果它是文本之间的字符串,则找到">"
的索引和"</"
的索引,然后将其子串。像这样: -
Sub Main()
Dim string_thathasvalue As String = "</skillAT>DEMDOMLOLIPOP90G</skillAT>"
Dim first_index As Integer
Dim second_index As Integer
Dim newstring As String = ""
For i = 0 To string_thathasvalue.Count - 1
If string_thathasvalue.Substring(i, 1) = ">" Then
first_index = i + 1
Exit For
End If
Next
For i = string_thathasvalue.Length - 2 To 0 - 1 Step -1
If string_thathasvalue.Substring(i, 2) = "</" Then
second_index = i
Exit For
End If
Next
Dim lengthofword As Integer = Math.Abs((first_index - second_index))
newstring = string_thathasvalue.Substring(first_index, lengthofword)
Console.WriteLine(newstring)
Console.ReadKey()
End Sub