c# 剔除 文件名中的非法字符 替换为同样式的其他字符


/// <summary>
        /// 替换文件名中的非法字符为同样式的其他字符
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string ReplaceFileName(string name)
        {
            name = name.Replace("/", "/");
            name = name.Replace("\\", "\");
            name = name.Replace(":", ":");
            name = name.Replace("*", "※");
            name = name.Replace("?", "?");
            name = name.Replace("\"", "“");
            name = name.Replace("<", "<");
            name = name.Replace(">", ">");
            name = name.Replace("|", "│");
            return
                name;
        }
C#快速剔除字符串中不合法的文件名

string strFileName= "文件名称"; 
StringBuilder rBuilder = new StringBuilder(strFileName); 
foreach(char rInvalidChar in Path.GetInvalidFileNameChars())        
rBuilder.Replace(rInvalidChar.ToString(), string.Empty);

C#快速剔除字符串中不合法的文件路径字符
string rPath = "路径"; 
StringBuilder rBuilder = new StringBuilder(rPath); 
foreach(char rInvalidChar in Path.GetInvalidPathChars())        
rBuilder.Replace(rInvalidChar.ToString(), string.Empty);
相关文章
相关标签/搜索
精选24码期期准小鱼儿