📄 districtcode.cs
字号:
using System;
class DistrictCode
{
public static void Main()
{
while(true)
{
Console.Write("请输入(输入“e”退出):");
string inputString = Console.ReadLine();
if( inputString == "e")
{
break;
}
Console.WriteLine(TextToQwm(inputString));
}
}
public static string TextToQwm(string character)
{
string coding = "";
int i1 = 0;
int i2 = 0;
int i3 = 0;
for ( int i = 0; i < character.Length; i++ )
{
byte[] bytes = System.Text.Encoding.Default.GetBytes(character.Substring(i,1)); //取出二进制编码内容
i1 = (short)(bytes[0] );
if(bytes.Length != 1)
{
i2 = ( short)(bytes[1] );
i3 = 1;
}
else
{
i2=65536; i3=-1;
}
int chrasc = i1 * 256 + i2 - 65536;
if( chrasc > 0 && chrasc < 160)
{
Console.WriteLine( "只能输入汉字。");
}
else
{
if( i3 == -1)
{
Console.WriteLine( "只能输入汉字。");
}
else
{
string lowCode = System.Convert.ToString( Math.Abs( Convert.ToInt32(System.Convert.ToString(bytes[0]))-160));//取出低字节编码内容(两位16进制)
if ( lowCode.Length == 1)
lowCode = "0" + lowCode;
string hightCode = System.Convert.ToString( Math.Abs(Convert.ToInt32(System.Convert.ToString(bytes[1]))-160));//取出高字节编码内容(两位16进制)
if ( hightCode.Length == 1)
hightCode = "0" + hightCode;
coding += character.Substring(i,1) + (lowCode + hightCode) ;//加入到字符串中,
}
}
}
return coding;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -