⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 《c#技术内幕代码》
💻 CS
字号:
using System;
using System.IO;

namespace CH14_7
{
	class Class1
	{
		public static string Pad( string s, int len )
		{
			string temp = s;
			for ( int i=s.Length; i<len; ++i )
				temp = "0" + temp;
			return temp;
		}
		static void Main(string[] args)
		{
			StreamReader sr = null;

			// Verify we received an argument to dump
			if ( args.Length < 1 )
			{
				System.Console.WriteLine("Usage: ch14_7 <filename>");
				return;
			}
			try 
			{
				// Try to open the file
				sr = new StreamReader( args[0] );
			}
			catch ( Exception e )
			{
				System.Console.WriteLine("Error opening file {0}", e);
				return;
			}
			string line = "";
			int nCounter = 0;
			int nOffset = 0;
			while ( (line = sr.ReadLine()) != null )
			{

				for ( int i=0; i<line.Length; ++i )
				{
					int c = (int)line[i];
					string fmt = String.Format("{0:x}", c);

					// Pad the format out to 2 digits
					if ( fmt.Length == 1 )
						fmt = Pad(fmt, 2);

					if ( nOffset % 16 == 0 )
					{
						string offsetFmt = nOffset.ToString();

						System.Console.Write(Pad(offsetFmt,5)+": ");
					}

					System.Console.Write(fmt + " ");
					if ( nCounter == 15 )
					{
						System.Console.Write("\n");
						nCounter = 0;
					}
					else
						nCounter ++;
					nOffset ++;
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -