How to replace a substring in Visual Basic?

OK, I am extremely sorry for my noisiness but I have a question involving the string replace function in Visual Basic. Though this seems simple, and probably is, I have searched everywhere and no found an answer. Here is my question:

I have a Visual Basic script for my project. I have a rich text box named 'sample'

Dim string1 as string = "text to find"
Dim string2 as string = "text to replace find with"
Dim mediacurrent as string

mediacurrent = sample.text

mediacurrent.replace(string1, string2)

sample.text = mediacurrent

The above script returns a blank text box. Note the text box is rich and contains non-formatted but multiline text. What am I doing wrong?


Strings are immutable in .NET, the Replace method returns the new value, it doesn't modify the original string on which it was called. You need to reassign it, like this:

mediacurrent = mediacurrent.Replace(string1, string2)


 ? Batch file: How to replace "=" (equal signs) and a string variable?
 ? Find/Replace text in a file using a batch file
 ? Searching a txt file for a line and deleting the subsequent 13 lines in a batch file
 ? Batch for insert/replace in a txt file in a fixed position
 ? Batch Script - Find and replace text in multiple files in a directory
 ? Find and replace line starts with specific value in text file via windows batch file
 ? Remove folders from txt file in windows cmd
 ? replacing line in txt file AFTER specific line
 ? How to concatenate 2 .csv files in 1 .csv file with multiple sheets using Batch commands
 ? How to remove strings from a text file using batch script?