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 replace a special character from a String
Let’s say our string is −
string str = "abcd$ef$gh";
To replace the special character, use the Replace() method.
string res = str.Replace('$', 'k');
The following is the complete code to replace character from a string −
Example
using System;
public class Program {
public static void Main() {
string str = "abcd$ef$gh";
Console.WriteLine("Initial string = " + str);
string res = str.Replace('$', 'k');
// after replacing
Console.WriteLine("Replaced string = " + res.ToString());
}
}
Output
Initial string = abcd$ef$gh Replaced string = abcdkefkgh
Advertisements