C # Remove illegal characters in the file name to replace other characters in the same style

/// 

/// Replace illegal characters in the file name with other characters of the same type
///

///
///
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#Quickly remove Invalid file name in the string


string strFileName= "File name";
StringBuilder rBuilder = new StringBuilder(strFileName);
foreach(char rInvalidChar in Path.GetInvalidFileNameChars())
rBuilder.Replace(rInvalidChar.ToString(), string.Empty);

C#Quickly remove illegal file path characters in the string
string rPath = "Path";
StringBuilder rBuilder = new StringBuilder(rPath);
foreach(char rInvalidChar in Path.GetInvalidPathChars())
rBuilder.Replace(rInvalidChar.ToString(), string.Empty);

< div class="CodeMirror-lines" role="presentation">

12

​ < /div>
10

11

< div class="" style="position: relative;">

12

/// 

/// Replace illegal characters in the file name with other characters of the same type
///

///
///
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;
}