I ran into the same problem and was concerned about the impact performance of the IsPunctuation call for each individual check.
I found this post: http://www.dotnetperls.com/char-ispunctuation .
Line by line: char.IsPunctuation also handles Unicode on top of ASCII. The method corresponds to a character set, including control characters. Definitely, this method is hard and expensive.
The bottom line is that I, in the end, did not go for it because of the impact of its performance on my ETL process.
I went for the usual dotnetperls implementation.
And jut FYI, here is the code deduced from previous answers to get a list of all punctuation marks (excluding control ones):
var punctuationCharacters = new List<char>(); for (int i = char.MinValue; i <= char.MaxValue; i++) { var character = Convert.ToChar(i); if (char.IsPunctuation(character) && !char.IsControl(character)) { punctuationCharacters.Add(character); } } var commaSeparatedValueOfPunctuationCharacters = string.Join("", punctuationCharacters); Console.WriteLine(commaSeparatedValueOfPunctuationCharacters);
Cheers, Andrew
andrew Apr 18 '15 at 22:05 2015-04-18 22:05
source share