
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- C++ Program to Print first letter of each word using regex
- Java Program to Print first letter of each word using regex
- Golang 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#
- How to capitalize the first letter of each word in a string using JavaScript?
- Extracting each word from a string using Regex in Java
- Capitalizing first letter of each word JavaScript
- 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?
- Return String by capitalizing first letter of each word and rest in lower case with JavaScript?
- Capitalize last letter and Lowercase first letter of a word in Java
- Python program to capitalize each word's first letter
- Array filtering using first string letter in JavaScript
- Golang program to capitalize first character of each word in a string

Advertisements