
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 All Spaces in a String with %20 in C#
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