19 lines
643 B
C#
19 lines
643 B
C#
using System.Text.RegularExpressions;
|
|
|
|
namespace LANCommander.Server.Extensions
|
|
{
|
|
public static class StringExtensions
|
|
{
|
|
public static string SanitizeFilename(this string filename, string replacement = "")
|
|
{
|
|
var removeInvalidChars = new Regex($"[{Regex.Escape(new string(Path.GetInvalidFileNameChars()))}]", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
|
|
|
return removeInvalidChars.Replace(filename, replacement);
|
|
}
|
|
|
|
public static string ToPath(this string path)
|
|
{
|
|
return Path.Combine(path.Split("/"));
|
|
}
|
|
}
|
|
}
|