किसी कैरेक्टर को एस्टेरिस्क से बदलने के लिए Replace() विधि का उपयोग करें।
मान लें कि हमारी स्ट्रिंग है:
string str = "dem* text";
इसे बदलने के लिए, Replace() विधि का उपयोग करें:
str.Replace('*', 'o');
यहां पूरा कोड है:
उदाहरण
using System;
public class Program {
public static void Main() {
string str = "dem* text";
Console.WriteLine("Initial string = " + str);
string res = str.Replace('*', 'o');
// बदलने के बाद
Console.WriteLine("After replacing asterisk = " + res.ToString());
}
}
आउटपुट
Initial string = dem* text After replacing asterisk = demo text