
- 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 all spaces in a string with β%20β
We have a sample string with spaces −
str ="Hello World !";
Use the Replace() method in C# to replace all spaces in a string with ‘%20’ −
str2 = str.Replace(" ", "%20");
Example
You can try to run the following code to replace all spaces in a string with ‘%20’.
using System; class Demo { static void Main() { String str, str2; str ="Hello World !"; Console.WriteLine("String: "+str); str2 = str.Replace(" ", "%20"); Console.WriteLine("String (After replacing): "+str2); } }
Output
String: Hello World ! String (After replacing): Hello%20World%20!
- Related Articles
- Golang program to replace the spaces of string with a specific character
- Java Program to Replace the Spaces of a String with a Specific Character
- Python Program to Replace all Occurrences of βaβ with $ in a String
- Java Program to remove all white spaces from a String.
- Replace All Consonants with Nearest Vowels In a String using C++ program
- Java Program to replace all occurrences of given String with new one
- C program to replace all occurrence of a character in a string
- Java program to remove all the white spaces from a given string
- How to replace all occurrences of a string with another string in Python?
- Java Program to replace all occurrences of a given character in a string
- How to replace multiple spaces with a single space in C#?
- How to replace leading zero with spaces - JavaScript
- Capitalize a word and replace spaces with underscore - JavaScript?
- How to replace multiple spaces in a string using a single space using Java regex?
- How to strip all spaces out of a string in PHP?

Advertisements