सबसे पहले, बदली जाने वाली स्ट्रिंग सेट करें।
string str = "Demo text!";
अब उपरोक्त स्ट्रिंग को बदलने के लिए replace() विधि का उपयोग करें।
string res = str.Replace("Demo ", "New ");
स्ट्रिंग में शब्द बदलने का पूरा कोड निम्नलिखित है।
उदाहरण
using System;
public class Demo {
public static void Main() {
string str = "Demo text!";
Console.WriteLine(str);
string res = str.Replace("Demo ", "New ");
Console.WriteLine("After replacing...");
Console.WriteLine(res);
}
}
आउटपुट
Demo text! After replacing... New text!