Powered by GeSHi

Source code for chr.cs

(view source code of chr.cs as plain text)

  1. using System;
  2.  
  3. namespace RobvanderWoude
  4. {
  5. 	class Chr
  6. 	{
  7. 		static int Main( string[] args )
  8. 		{
  9. 			if ( args.Length != 1 )
  10. 			{
  11. 				return WriteError( );
  12. 			}
  13. 			try
  14. 			{
  15. 				if ( Convert.ToInt32( args[0] ).ToString( ) != args[0] )
  16. 				{
  17. 					return WriteError( );
  18. 				}
  19. 				if ( Convert.ToInt32( args[0] ) > 255 || Convert.ToInt32( args[0] ) < 0 )
  20. 				{
  21. 					return WriteError( );
  22. 				}
  23. 				Console.WriteLine( "{0}", Convert.ToChar( Convert.ToByte( Convert.ToInt32( args[0] ) ) ) );
  24. 			}
  25. 			catch ( Exception )
  26. 			{
  27. 				return WriteError( );
  28. 			}
  29. 			return 0;
  30. 		}
  31.  
  32. 		public static int WriteError( )
  33. 		{
  34. 			/*
  35. 			Chr,  Version 1.00
  36. 			Return the ASCII character for the specified decimal character code
  37.  
  38. 			Usage:  CHR  charcode
  39.  
  40. 			Where:  charcode  is a decimal number in the range 0..255
  41.  
  42. 			Written by Rob van der Woude
  43. 			http://www.robvanderwoude.com
  44. 			*/
  45.  
  46. 			Console.Error.WriteLine( );
  47. 			Console.Error.WriteLine( "Chr,  Version 1.00" );
  48. 			Console.Error.WriteLine( "Return the ASCII character for the specified decimal character code" );
  49. 			Console.Error.WriteLine( );
  50. 			Console.Error.Write( "Usage:  " );
  51. 			Console.ForegroundColor = ConsoleColor.White;
  52. 			Console.Error.WriteLine( "CHR  charcode" );
  53. 			Console.ResetColor( );
  54. 			Console.Error.WriteLine( );
  55. 			Console.Error.Write( "Where:  " );
  56. 			Console.ForegroundColor = ConsoleColor.White;
  57. 			Console.Error.Write( "charcode" );
  58. 			Console.ResetColor( );
  59. 			Console.Error.WriteLine( "  is a decimal number in the range 0..255" );
  60. 			Console.Error.WriteLine( );
  61. 			Console.Error.WriteLine( "Written by Rob van der Woude" );
  62. 			Console.Error.WriteLine( "http://www.robvanderwoude.com" );
  63. 			return 1;
  64. 		}
  65. 	}
  66. }
  67.