Следующая ссылка показывает это очень четко: http://www.dotnetperls.com/replace Если вы используете string.Replace, его нужно назначить (как упомянуто выше Geeklat):
String newString = "b00k";
newString = newString.Replace('0', 'o');
Если вы используете "StringBuilder "переменная не должна быть назначена - вот пример программы (вывод ниже):
using System;
using System.Text;
class Program
{
static void Main()
{
const string s = "This is an example.";
// A
// Create new StringBuilder from string
StringBuilder b = new StringBuilder(s);
Console.WriteLine(b);
// B
// Replace the first word
// The result doesn't need assignment
b.Replace("This", "Here");
Console.WriteLine(b);
// C
// Insert the string at the beginning
b.Insert(0, "Sentence: ");
Console.WriteLine(b);
}
}
Вывод:
This is an example.
Here is an example.
Sentence: Here is an example.