I have done research but my app downloads mp3 files every once in a while I get weird filename which doesn't hurt until I try to burn them to CD. Below is a good example. The Animals - House of the Rising Sun (1964) + clip compilation ♫♥ 50 YEARS - counting.mp3 I have some code to try and catch illegal characters but it doesn't stop this filename. Is there a better way to catch the weird stuff the code I use currently is:
public static string RemoveIllegalFileNameChars(string input, string replacement = "")
{
if (input.Contains("?"))
{
input = input.Replace('?', char.Parse(" "));
}
if (input.Contains("&"))
{
input = input.Replace('&', char.Parse("-"));
}
var regexSearch = new string(Path.GetInvalidFileNameChars()) +
new string(Path.GetInvalidPathChars());
var r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
return r.Replace(input, replacement);
}