मान लें कि हमारा स्ट्रिंग है -
string str = "The Shape of Water got an Oscar Award!";
प्रत्येक शब्द का पहला अक्षर प्रदर्शित करने के लिए निम्नलिखित नियमित अभिव्यक्ति का प्रयोग करें -
@"\b[a-zA-Z]"
यहाँ पूरा कोड है -
उदाहरण
using System;
using System.Text.RegularExpressions;
namespace RegExApplication {
public class Program {
private static void showMatch(string text, string expr) {
Console.WriteLine("The Expression: " + expr);
MatchCollection mc = Regex.Matches(text, expr);
foreach (Match m in mc) {
Console.WriteLine(m);
}
}
public static void Main(string[] args) {
string str = "The Shape of Water got an Oscar Award!";
Console.WriteLine("Display first letter of each word!");
showMatch(str, @"\b[a-zA-Z]");
}
}
} आउटपुट
Display first letter of each word! The Expression: \b[a-zA-Z] T S o W g a O A