Remove non printable characters C# multilanguage

c#

Solution

Assuming you mean the name of the ZIP file, instead of the names inside the ZIP file, you probably want to check if the character is valid for a filename, which will allow you to use more than just letters or digits:

char[] invalid = System.IO.Path.GetInvalidFileNameChars();

string s = "abcöü*/";
var newstr = new String(s.Where(c => !invalid.Contains(c)).ToArray()); 

Problem

I have a multi-language application in asp.net C#. Here I have to create a zip file and use some items from the database to construct file name. I strip out special characters from file name. However if the language is German for example my trimming algorithm will remove some german characters like Umlaut. Could someone provide me with a language adaptable trimming algorithm. Here is my code: ``` private string RemoveSpecialCharacters(string str) { return str; StringBuilder sb = new StringBuilder(); foreach (char c in str) { if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') | c == '.' || c == '_' || c == ' ' || c == '+') { sb.Append(c); } } return sb.ToString(); } ``` thanks

Original source