How do you replace all instances in a richtextbox?
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
Hello,
How can I make my code (below) replace all instances of the given text, instead of just one instance?
Code:
~GoodGuy17
How can I make my code (below) replace all instances of the given text, instead of just one instance?
Code:
Code: Select all
Please help! 'Find and replace
Try
Dim strFind As String = InputBox("Enter string you want to replace. Enter 'No' if you don't want to find only whole words.", "Find")
If strFind = "No" Then
Dim strFind2 As String = InputBox("Enter string you want to replace.", "Find")
Dim strReplace As String = InputBox("Enter string you want to replace with.", "Replace with")
RichTextBox1.Find(strFind2, RichTextBoxFinds.None)
RichTextBox1.SelectedText = strReplace
Else
Dim strReplace2 As String = InputBox("Enter string you want to replace with.", "Replace with")
RichTextBox1.Find(strFind, RichTextBoxFinds.WholeWord)
RichTextBox1.SelectedText = strReplace2
End If
Catch ex As Exception
MsgBox(ex)
End Try
~GoodGuy17

Code: Select all
RichTextBox1.Text.Replace(original, new)
Didn't work. It didn't replace anything.
Put this under Replace All button click event
TextBox1 - The text which you want to replace
TextBox2 - The text with which you want the TextBox1 text to be replaced.
If you like my posts please give me +rep!! cooll;
Code: Select all
In this code - Dim cp As Integer = RichTextBox1.SelectionStart
Dim cs As Integer = RichTextBox1.SelectionLength
RichTextBox1.Rtf = Replace(RichTextBox1.Rtf, Trim(TextBox1.Text), Trim(TextBox2.Text))
RichTextBox1.SelectionStart = cp
RichTextBox1.SelectionLength = cs
Me.Focus()
TextBox1 - The text which you want to replace
TextBox2 - The text with which you want the TextBox1 text to be replaced.
If you like my posts please give me +rep!! cooll;
Instead of LOL use this -
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
Thanks CoderBoy! You've got it! cooll;
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023