陋室铭
永远也不要停下学习的脚步(大道至简至易)

 

 

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();
    }

 

posted on 2021-08-23 19:15  宏宇  阅读(540)  评论(0编辑  收藏  举报