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