Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for chr.cs

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

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

page last uploaded: 2015-12-04, 16:51
Fileaze