Skip to content

Instantly share code, notes, and snippets.

@behnood-eghbali
Created April 12, 2021 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save behnood-eghbali/cbf7d384694100c2dc07ae1610964e87 to your computer and use it in GitHub Desktop.
Save behnood-eghbali/cbf7d384694100c2dc07ae1610964e87 to your computer and use it in GitHub Desktop.
urlify strings with/without regex (c#)
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