0

I have a question involving the string Replace function in Visual Basic .NET:

I have a Visual Basic script for my project. I have a RichTextBox 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?

0

1 Answer 1

9

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)
Sign up to request clarification or add additional context in comments.

Comments

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.