• Home
  • About
    • Coding Recipes photo

      Coding Recipes

    • Learn More
    • Email
    • Twitter
    • Facebook
    • LinkedIn
    • Instagram
    • Github
  • Posts
    • All Posts
    • All Tags

URLify

30 Dec 2020

Reading time ~1 minute

Replace all spaces in a string with “%20”. Ignore leading and trailing spaces.

public class ArraysAndStrings
{
	public string Urlify(string str){
		str = str.Trim();
		str = str.Replace(" ", "%20");

        return str;
    }
}

A solution using Ruby:

def urlify(str)
	str.strip.gsub(" ", "%20")
end



stringsoftwarecodearray