
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
Replace Character with Asterisks in a Sentence using C#
Use the Replace() method to replace a character with asterisks.
Let’s say our string is −
string str = "dem* text";
To replace it, use the Replace() method −
str.Replace('*', 'o');
Here is the complete code −
Example
using System; public class Program { public static void Main() { string str = "dem* text"; Console.WriteLine("Initial string = " + str); string res = str.Replace('*', 'o'); // after replacing Console.WriteLine("After replacing asterisk = " + res.ToString()); } }
Output
Initial string = dem* text After replacing asterisk = demo text
Advertisements