I created a method that takes in a string and checks for characters that typically doesn't play nice with URLs. All but the "&" char is being removed correctly.
Does anyone know why this is being ignored?
My Method:
public static string URLify (string deviceName)
{
deviceName.Replace("/", "-").Replace("&", "").Replace(" ", "-").Replace("+", "");
return deviceName;
}
Thank you Julian! I soon realized that .Replace doesn't modify the existing string, but returns a new string with your modifications. So I ended up doing as follows:
public static string URLify (string deviceName)
{
deviceName = deviceName.Replace("/", "-").Replace("&", "").Replace(" ", "-").Replace("+", "");
return deviceName;
}
You don't use the return value of the Replace method. Try this:
public static string URLify (string deviceName)
{
return deviceName.Replace("/", "-").Replace("&", "").Replace(" ", "-").Replace("+", "");
}
Zyth
Zachary Stone I believe in c# you can UrlEncode strings, and so eliminating the need for your function URLify.