C#返回指定ASCII码的十进制字符的代码

将写代码过程常用的内容做个收藏,下面代码内容是关于C#返回指定ASCII码的十进制字符的代码,应该能对小伙伴有些帮助。 using System;

namespace RobvanderWoude { class Asc { static int Main( string[] args ) { if ( args.Length != 1 ) { return WriteError( string.Empty ); } if ( args[0].Length != 1 ) { return WriteError( string.Empty ); } try { int result = Convert.ToInt32( Convert.ToByte( Convert.ToChar( args[0].Substring( 0, 1 ) ) ) ); Console.WriteLine( "{0}", result ); return result; } catch ( Exception e ) { return WriteError( e.Message ); } }

	public static int WriteError( Exception e )
	{
		return WriteError( e == null ? null : e.Message );
	}

	public static int WriteError( string errorMessage )
	{
		Asc,  Version 1.00
		Return the decimal character code for the specified ASCII character

		Usage:  ASC  character

		Where:  character  is an ASCII character

		Note:   The result will be displayed on screen and returned as exit
		        code ("errorlevel"); in case of errors, exit code will be 0.

		Written by Rob van der Woude

		if ( string.IsNullOrEmpty( errorMessage ) == false )
		{
			Console.Error.WriteLine( );
			Console.ForegroundColor = ConsoleColor.Red;
			Console.Error.Write( "ERROR: " );
			Console.ForegroundColor = ConsoleColor.White;
			Console.Error.WriteLine( errorMessage );
			Console.ResetColor( );
		}

		Console.Error.WriteLine( );
		Console.Error.WriteLine( "Asc,  Version 1.00" );
		Console.Error.WriteLine( "Return the decimal character code for the specified ASCII character" );
		Console.Error.WriteLine( );
		Console.Error.Write( "Usage:  " );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.WriteLine( "ASC  character" );
		Console.ResetColor( );
		Console.Error.WriteLine( );
		Console.Error.Write( "Where:  " );
		Console.ForegroundColor = ConsoleColor.White;
		Console.Error.Write( "character" );
		Console.ResetColor( );
		Console.Error.WriteLine( "  is an ASCII character" );
		Console.Error.WriteLine( );
		Console.Error.WriteLine( "Note:   The result will be displayed on screen and returned as exit" );
		Console.Error.WriteLine( "        code ("errorlevel"); in case of errors, exit code will be 0." );
		Console.Error.WriteLine( );
		Console.Error.WriteLine( "Written by Rob van der Woude" );
		return 0;
	}
}
复制代码

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值