Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textbox replace text

Tags:

c#

It give me an error, don't know why. I want to replace ' with ".

try
{
     txtCS.Text.Replace("'", """);
}
catch
{
}
like image 791
user974015 Avatar asked Apr 25 '26 12:04

user974015


1 Answers

The Replace method returns a string because strings themselves are immutable. This means that instead of changing the existing string (txtCS.Text), it creates a new string object and so you need to assign that new string object to the textbox.

Also, you're missing the escape character in your quotes. By adding a \, you can use the " character, otherwise the compiler thinks you're closing the string.

txtCS.Text = txtCS.Text.Replace("'", "\""); 
like image 112
keyboardP Avatar answered Apr 28 '26 01:04

keyboardP