2023-01-06 22:12:03 -06:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.SDK.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class StringExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string SanitizeFilename(this string filename, string replacement = "")
|
|
|
|
|
{
|
2023-01-07 12:57:58 -06:00
|
|
|
|
var colonInTitle = new Regex(@"(\w)(: )(\w)");
|
2023-01-06 22:12:03 -06:00
|
|
|
|
var removeInvalidChars = new Regex($"[{Regex.Escape(new string(Path.GetInvalidFileNameChars()))}]", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
|
|
|
|
|
2023-01-07 12:57:58 -06:00
|
|
|
|
filename = colonInTitle.Replace(filename, "$1 - $3");
|
|
|
|
|
filename = removeInvalidChars.Replace(filename, replacement);
|
|
|
|
|
|
|
|
|
|
return filename;
|
2023-01-06 22:12:03 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|