using System; namespace RobvanderWoude { class Chr { static string progver = "1.02"; static int Main( string[] args ) { if ( args.Length > 1 || ( args.Length ==1 && Console.IsInputRedirected ) ) { return ShowHelp( ); } try { string input; if ( Console.IsInputRedirected ) { input = Console.In.ReadToEnd( ); } else { input = args[0]; } if ( Convert.ToInt32( input ).ToString( ) != input ) { return ShowHelp( ); } if ( Convert.ToInt32( input ) > 255 || Convert.ToInt32( input ) < 0 ) { return ShowHelp( ); } Console.Write( "{0}", Convert.ToChar( Convert.ToByte( Convert.ToInt32( input ) ) ) ); } catch ( Exception ) { return ShowHelp( ); } return 0; } public static int ShowHelp( ) { /* Chr, Version 1.02 Return the ASCII character for the specified decimal character code Usage: CHR charcode or: some_program | CHR Where: charcode decimal number in the range 0..255 some_program program generating a decimal number in the range 0..255 Note: This version of CHR requires .NET framework 4.5. Written by Rob van der Woude https://www.robvanderwoude.com */ Console.Error.WriteLine( ); Console.Error.WriteLine( "Chr, Version {0}", progver ); Console.Error.WriteLine( "Return the ASCII character for the specified decimal character code" ); Console.Error.WriteLine( ); Console.Error.Write( "Usage: " ); Console.ForegroundColor = ConsoleColor.White; Console.Error.WriteLine( "CHR charcode" ); Console.ResetColor( ); Console.ForegroundColor = ConsoleColor.White; Console.Error.WriteLine( " or: " ); Console.Error.WriteLine( "some_program | CHR" ); Console.ResetColor( ); Console.ForegroundColor = ConsoleColor.White; Console.Error.Write( " some_program" ); Console.ResetColor( ); Console.Error.WriteLine( " program generating a decimal number in the range 0..255" ); Console.Error.WriteLine( ); Console.Error.Write( "Where: " ); Console.ForegroundColor = ConsoleColor.White; Console.Error.Write( "charcode" ); Console.ResetColor( ); Console.Error.WriteLine( " decimal number in the range 0..255" ); Console.Error.WriteLine( ); Console.Error.WriteLine( "Note: This version of CHR requires .NET framework 4.5." ); Console.Error.WriteLine( ); Console.Error.WriteLine( "Written by Rob van der Woude" ); Console.Error.WriteLine( "https://www.robvanderwoude.com" ); return 1; } } }