C#创建目录,文件名过滤特殊字符串,非法字符

 

 

string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());

foreach (char c in invalid)
{
    illegal = illegal.Replace(c.ToString(), ""); 
}

 

public string RemoveInvalidFileNameChars(string fileName)
{
if (string.IsNullOrWhiteSpace(fileName)) return null;

        string invalid = new string(Path.GetInvalidFileNameChars()); //new string(Path.GetInvalidPathChars());
        StringBuilder sb = new StringBuilder();
        //foreach (char c in invalid) {fileName = fileName.Replace(c.ToString(), "");}
        foreach (char c in fileName)
        {
            if (!invalid.Contains(c)) sb.Append(c);
        }
        return sb.ToString();
    }

 

C#创建目录,文件名过滤特殊字符串,非法字符

上一篇:【配置】jdk8和jdk11切换


下一篇:Odoo14 js 怎么获取图片url链接