c# 替換非法字符

保存文件的時候,文件名不容許非法字符。ci

 

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

 

 

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

相關文章
相關標籤/搜索