1

This is my code, I want to replace the word "here" with "potato" in the simplest way.

Private Sub btnreplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)      Handles btnreplace.Click
    txttyping.Text.Replace("here", "potato")
End Sub

2 Answers 2

3

Strings (text) are immutable. This means they cannot be changed directly, to alter one, a new string is created/returned.

txttyping.Text = txttyping.Text.Replace("here", "potato)

Replace() returns a new string which needs to be assigned. This is true for all the String methods which change the string: ToLower(), ToUpper(), Remove(), PadLeft(), Copy(), Remove(), TrimEnd().

See MSDN String Class:

A String object is called immutable (read-only), because its value cannot be modified after it has been created. Methods that appear to modify a String object actually return a new String object that contains the modification.

Sign up to request clarification or add additional context in comments.

Comments

0

since its a particular word you can use simple text replacement other than using regex.replace()

try this

txttyping.Text = Replace(txttyping.Text, "here", "potato")

here replace(sourcestring,findword,replaceword)

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.