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
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)
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.