0

how could i make that

Source_Source.Text (richtextbox) :

src="test.com" akalsjdjalksdv src="another.com" asdbnmslkbjcxv asdas as danms d amsn asdasd src="cold.com"asdas as dasd amnbs dma d sdf kjhds f src="find.com" asd kja sdasjhk d asdsrc="other.com" a jksdh asksjd hasdjh src="found.com"

what if i wanna get random src=" ", for example, if i clicked butten will show message = src="test.com" , another time if i clicked button will show another random, for example src="another.com" ,

my currently code only select first string which = src="test.com" , and i wanna select randoms src="[random test / cold / other / found / find]"

for example my next click can show message for src="find.com" that for example.

my code :

 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

2 Answers 2

1
Private Function RndUrl() As String
    Dim UrlStr() As String = {"whatever.com", "whatever2.com"}
    Return Rand.Next(0, UrlStr.Length) '"Rand" Declared at Class scope as Random
End Function

Usage:

    TextBox1.Text = "src=""" & RndUrl() & ""
Sign up to request clarification or add additional context in comments.

2 Comments

Error : 'Rand' is not declared. It may be inaccessible due to its protection level.
declare it as Public Shared
0

If I understand your question correctly, you're looking for a certain phrase in a String? If so look into String.Contains() method. For example:

If Source_Source.Text.Contains(Search_1.Text) Then
    ' Do you're logic here if found
    Source_Source.Text.SubString(0, 5) ' Or where ever that part of the string is that you want.
End If

2 Comments

let me clear it more, if i wanna get random link from webpage source and its start daily with [src="], and put it in richtextbox so now i wanna get random src links that found , with every click.
Give this link a shot. link It uses the Random class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.