Let's say that I want to display some random text that the user will later need to be able to enter on the keyboard. I want to avoid using characters that the use will not be familiar with and may not know how to enter. For example, for English speakers, I want to avoid accented letters such as French "é".
I had thought that the CultureInfo class would provide information about the character set used by a culture, but I didn't find anything that seemed to help.
I can quickly get the US English character set either by hard coding it or using a function like this (in C#):
public string GetCharacterSet() { return (Enumerable.Range(32, 95).Select((i) => Convert.ToChar(i)).ToArray).ToString(); }
I'm not sure how to do this reliably for other cultures. I can code the function like this (in VB):
Function GetCharacterSet() As String Dim chars As New List(Of Char) For i As Integer = 0 To UInt16.MaxValue Dim ch As Char = ChrW(i) If Char.IsLetterOrDigit(ch) OrElse Char.IsPunctuation(ch) OrElse ch = " "c Then chars.Add(ch) End If Next Return chars.ToArray End Function
But the resulting (very long) string contains all characters that are valid inany culture. Is there a way to check if a character is a letter, digit or punctuation in thecurrent culture only?