 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Replace parts of a string with C# Regex
Set a string −
string str = "Bit and Bat";
Let’s say you need to replace whatever comes inside B and t to A and capitalize the complete string. For that, use Replace −
Regex.Replace(str, "B.t", "BAT");
Let us see the complete code −
Example
using System; using System.Text.RegularExpressions; namespace Demo {    class Program {       static void Main(string[] args) {          string str = "Bit and Bat";          Console.WriteLine(str);          string res = Regex.Replace(str, "B.t", "BAT");          Console.WriteLine(res);       }    } }  Output
Bit and Bat BAT and BAT
Advertisements
 