
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
C# Program to Remove the End Part of a String
Use the Regex.Replace method to remove the end part of a string in C#.
The following is the string −
string s1 = "Demo Text!";
Now, let us say you need to remove the exclamation mark (!) from the string. For that just set it to empty using replace −
System.Text.RegularExpressions.Regex.Replace(s1, "!", "");
Here is the complete code −
Example
using System; using System.Text.RegularExpressions; namespace Demo { class Program { static void Main(string[] args) { string s1 = "Demo Text!"; // replace the end part string s2 = System.Text.RegularExpressions.Regex.Replace(s1, "!", ""); Console.WriteLine("\"{0}\"
\"{1}\"", s1, s2); } } }
Output
"Demo Text!" "Demo Text"
Advertisements