Simple Replace Text In TextBox - Help Needed
Here is what i have so far
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim r As New Random
Label1.Text = r.Next(1, 5)
If Label1.Text = "1" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "resgg")
ElseIf Label1.Text = "2" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "thnks")
ElseIf Label1.Text = "3" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "please")
ElseIf Label1.Text = "4" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "overs")
ElseIf Label1.Text = "5" Then
RichTextBox1.Text = Replace(RichTextBox1.Text, TextBox1.Text, "tester")
End If
At the moment i have to enter text in Textbox1 that i want to replace, and then when i click the button it will replace it with a random entry from the list.
That's great but ideally i want a solution where i can select text in the RichTextBox1 between markers like * or / and replace the chosen text on every button click, not just once.
At the moment it replaces text in the RichTextBox1 only once. I need it to do it every time i click the button.
It is for a content rewriter.
Any help greatly appreciated. :)
Re: Simple Replace Text In TextBox - Help Needed
Firstly, your random would never return 5. You'll have to call r.Next(Min, Max + 1) for it to work properly.
Secondly, you might want to use an array to hold the strings, and a variable to hold the number, not a label. Like so:
Code:
Dim R As New System.Random, I As Int32 = R.Next(0, 4 + 1)
Dim Strings() As String = {"resgg", "thnks", "please", "overs", "tester"}
Me.RichTextBox1.Text = Replace(Me.RichTextBox1.Text, Me.TextBox1.Text, Strings(I))
Thirdly.. I'm not quite sure what you're trying to do. What do you mean it does it only once?
Re: Simple Replace Text In TextBox - Help Needed
ideally i want to be able to select a piece of text in brackets in the richtextbox, like this..
{this is an} example of text here
and have the text in brackets change to to a random value in the list, every time i click the button.
so on button click one...
"please example of text here"
so on button click two
"thnks example of text here"
Re: Simple Replace Text In TextBox - Help Needed
What kind of application is this? :confused:
Changing existing text into something randem doesn't sound healthy.
Re: Simple Replace Text In TextBox - Help Needed