Replace colons in titles with hyphens for file safety

dashboard
Pat Hartl 2023-01-07 12:57:58 -06:00
parent fead35e612
commit c571058817
1 changed files with 5 additions and 1 deletions

View File

@ -7,9 +7,13 @@ namespace LANCommander.SDK.Extensions
{
public static string SanitizeFilename(this string filename, string replacement = "")
{
var colonInTitle = new Regex(@"(\w)(: )(\w)");
var removeInvalidChars = new Regex($"[{Regex.Escape(new string(Path.GetInvalidFileNameChars()))}]", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.CultureInvariant);
return removeInvalidChars.Replace(filename, replacement);
filename = colonInTitle.Replace(filename, "$1 - $3");
filename = removeInvalidChars.Replace(filename, replacement);
return filename;
}
}
}