Created
April 12, 2021 14:58
-
-
Save behnood-eghbali/cbf7d384694100c2dc07ae1610964e87 to your computer and use it in GitHub Desktop.
urlify strings with/without regex (c#)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text.RegularExpressions; | |
namespace Urlify | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var newString = "How to make pancakes "; | |
var trimmedString = newString.Trim(); | |
// without regex | |
var replacedString = trimmedString.Replace(" ", "%20"); | |
Console.WriteLine(replacedString); | |
// with regex | |
var urlifiedString = Regex.Replace(trimmedString, @"\s+","%20"); | |
Console.WriteLine(urlifiedString); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment