【发布时间】:2019-05-06 19:49:42
【问题描述】:
我是怎么做到的
Source_Source.Text(富文本框):
src="test.com"akalsjdjalksdvsrc="another.com"asdbnmslkbjcxv asdas as danms d amsn asdasdsrc="cold.com"asdas as dasd amnbs dma d sdf kjhds fsrc="find.com"asd kja sdasjhk d asdsrc="other.com"a jksdh asksjd hasdjhsrc="found.com"
如果我想得到随机 src=" " 怎么办,例如,如果我点击 butten 将显示 message = src="test.com" ,如果我再次点击按钮将显示另一个随机,例如 src="another.com" ,
我目前的代码只选择第一个字符串 which = src="test.com" ,我想随机选择 src="[random test / cold / other / found / find]"
例如,我的下一次点击可以显示src="find.com" 的消息,例如。
我的代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sSource As String = Source_Source.Text 'String that is being searched
Dim sDelimStart As String = Search_1.Text 'First delimiting word
Dim sDelimEnd As String = Search_2.Text 'Second delimiting word
Dim nIndexStart As Integer = sSource.IndexOf(sDelimStart) 'Find the first occurrence of f1
Dim nIndexEnd As Integer = sSource.IndexOf(sDelimEnd, nIndexStart + sDelimStart.Length + 1) '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
End Sub
【问题讨论】:
标签: vb.net