- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- C# program to replace n-th character from a given index in a string
- C# program to check if a string contains any special character
- C program to replace all occurrence of a character in a string
- Program to check if a string contains any special character in C
- PHP program to check if a string has a special character
- C# Program to change a character from a string
- Java program to check if a string contains any special character
- Program to check if a string contains any special character in Python
- C++ Program to Replace a Character at a Specific Index
- C# program to remove n-th character from a string
- Java Program to replace all occurrences of a given character in a string
- Java Program to Replace the Spaces of a String with a Specific Character
- C# Program to replace a character with asterisks in a sentence
- JAVA Menu Driven Program to Check Character is String, Number or Special Character
- How to replace a character in Objective-C String for iPhone SDK?

Advertisements