c# 替换非法字符

保存文件的时候,文件名不允许非法字符。

public string ReplaceSpecialCharacter(string str)
        {
            List<char> charArr = new List<char>() { '\\', '/', '*', '?', '"', '<', '>', '|', ':' };
            return charArr.Aggregate(str, (current, c) => current.Replace(c, ' '));
        }

public string ReplaceSpecialCharacterV2(string str)
{
List<string> charArr = new List<string>() { "\\", "/", "*", "?", "<", ">", "|", ":" ,"\""};
return charArr.Aggregate(str, (current, c) => current.Replace(c, ""));
}

上一篇:GoogleCodeJam


下一篇:python3+arcface2.0 离线人脸识别 demo