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;
        }
19
 
1
 /// <summary>
2
 /// 替換文件名中的非法字符爲一樣式的其餘字符
3
 /// </summary>
4
 /// <param name="name"></param>
5
 /// <returns></returns>
6
 public string ReplaceFileName(string name)
7
 {
8
 name = name.Replace("/", "/");
9
 name = name.Replace("\\", "\");
10
 name = name.Replace(":", ":");
11
 name = name.Replace("*", "※");
12
 name = name.Replace("?", "?");
13
 name = name.Replace("\"", "「");
14
 name = name.Replace("<", "<");
15
 name = name.Replace(">", ">");
16
 name = name.Replace("|", "│");
17
 return
18
 name;
19
 }
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);
12
 
1
C#快速剔除字符串中不合法的文件名
2
3
string strFileName= "文件名稱"; 
4
StringBuilder rBuilder = new StringBuilder(strFileName); 
5
foreach(char rInvalidChar in Path.GetInvalidFileNameChars()) 
6
rBuilder.Replace(rInvalidChar.ToString(), string.Empty);
7
8
C#快速剔除字符串中不合法的文件路徑字符
9
string rPath = "路徑"; 
10
StringBuilder rBuilder = new StringBuilder(rPath); 
11
foreach(char rInvalidChar in Path.GetInvalidPathChars()) 
12
rBuilder.Replace(rInvalidChar.ToString(), string.Empty);
相關文章
相關標籤/搜索