

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print first letter of each word in a string using C# regex
Let’s say our string is −
string str = "The Shape of Water got an Oscar Award!";
Use the following Regular Expression to display first letter of each word −
@"\b[a-zA-Z]"
Here is the complete code −
Example
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]"); } } }
Output
Display first letter of each word! The Expression: \b[a-zA-Z] T S o W g a O A
- Related Questions & Answers
- Java Program to Print first letter of each word using regex
- Getting first letter of each word in a String using regex in Java
- Print first letter of each word in a string in C#
- Capitalizing first letter of each word JavaScript
- How to capitalize the first letter of each word in a string using JavaScript?
- Extracting each word from a string using Regex in Java
- How to get first letter of each word using regular expression in Java?
- How to print the first character of each word in a String in Java?
- Python program to capitalize each word's first letter
- Return String by capitalizing first letter of each word and rest in lower case with JavaScript?
- Java Program to Capitalize the first character of each word in a String
- Array filtering using first string letter in JavaScript
- Make first letter of a string uppercase in JavaScript?
- Find frequency of each word in a string in C#
- Find frequency of each word in a string in Java
Advertisements