सबसे पहले, स्ट्रिंग को बदलने के लिए सेट करें।
string str = "Demo text!";
अब उपरोक्त स्ट्रिंग को बदलने के लिए रिप्लेस () विधि का उपयोग करें।
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!