c# 去除不可作为文件名的特殊符号

        /// <summary>
        /// 去除特殊字符
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string MakeValidFileName(string text)
        {
            StringBuilder str = new StringBuilder();
            var invalidFileNameChars = Path.GetInvalidFileNameChars();
            foreach (var c in text)
            {
                if (!invalidFileNameChars.Contains(c))
                {
                    str.Append(c);
                }
            }

            return str.ToString();
        }

 

posted @ 2021-05-13 07:49  simadi  阅读(898)  评论(0编辑  收藏  举报