System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex( "[^\x00-\x7F]" ); if ( regex.IsMatch( testString ) ) { //Nicht-ASCII-Zeichen gefunden }
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex( "(^\x00-\x7F)" ); System.Text.RegularExpressions.MatchCollection matches = regex.Matches( testString ); foreach ( System.Text.RegularExpressions.Match match in matches ) { //Nicht-ASCII-Zeichen-Gruppe gefunden }
Encoding.ASCII.GetString( (byte[])testString, 0, testString.Length );
string testString = "Halööö Welt. Hähähäh!!!"; byte[] byteArray = Encoding.ASCII.GetBytes( testString ); Console.WriteLine( Encoding.ASCII.GetString( byteArray, 0, byteArray.Length ) );
Theme based on MadsSimple dasBlog theme by Mads Kristensen
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.