Remove/Replace invalid characters in string (c# / .NET)
private string RemoveInvalidFilePathCharacters(string filename, string replaceChar)
{
string regexSearch = new string(System.IO.Path.GetInvalidFileNameChars()) + new string(System.IO.Path.GetInvalidPathChars());
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(string.Format("[{0}]", System.Text.RegularExpressions.Regex.Escape(regexSearch)));
return r.Replace(filename, replaceChar);
}
No comments:
Post a Comment