- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 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!
Advertisements