I try to make it possible for users to search for customers with a quote in the CustomerName.
The user search the user in the customerNameTextBox wich is set to the customerNameTB.
If the user uses a quote(') it will be replaced with a double-quote.
And if there is a triple quote(''') it will be replaced with a double-quote.
Here is my code:
string customerNameTB = customerNameTextbox.Text;
customerNameTB.Replace("'", "''");
while (customerNameTB.Contains("'''"))
{
customerNameTB.Replace("'''", "''");
}
The result after this code is the quotes are still single quotes.
Whats is wrong with this little piece of code..
Edit after answers
My code should look like this:
string customerNameTB = customerNameTextbox.Text;
customerNameTB = customerNameTB.Replace("'", "''");
while (customerNameTB.Contains("'''"))
{
customerNameTB = customerNameTB.Replace("'''", "''");
}
You're close! This is what you need:
The replace doesn't replace it in the original string, it returns a new string that you have to assign to something or it just gets thrown away.