
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# Program to replace a character with asterisks in a sentence
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
- Related Articles
- Python Program to replace a word with asterisks in a sentence
- Java Program to replace a word with asterisks in a sentence
- PHP program to replace a word with a different symbol in a sentence
- C# Program to convert first character uppercase in a sentence
- C Program to convert first character uppercase in a sentence
- C# Program to replace a special character from a String
- C++ Program to Replace a Character at a Specific Index
- Program to reverse a sentence words stored as character array in C++
- C program to replace all occurrence of a character in a string
- Java Program to replace all occurrences of a given character with new character
- Java Program to convert first character uppercase in a sentence
- Java Program to Replace the Spaces of a String with a Specific Character
- Python Program to Replace the Spaces of a String with a Specific Character
- C# program to replace n-th character from a given index in a string
- C++ Program to find matrix with marked asterisks region

Advertisements