62,041
社区成员
发帖
与我相关
我的任务
分享
public static string convert(string chrstr)
{
byte[] array = new byte[2];
string returnstr= " ";
int chrasc=0;
int i1 = 0;
int i2 =0;
char[] nowchar=chrstr.ToCharArray();
for (int j=0;j <nowchar.Length ;j++)
{
//增加了对字符长度判断的处理,避免了因为字符串中存在英文、数字而引起的异常
byte[] btchk = System.Text.Encoding.Default.GetBytes(nowchar[j].ToString ());
if(btchk.Length == 1)
{
returnstr+=nowchar[j].ToString();
continue;
}
array = btchk;
i1 = (short)(array[0] );
i2 = (short)(array[1] );
chrasc=i1*256+i2-65536;
if (chrasc> 0 && chrasc <160)
{
returnstr+=nowchar[j];
}
else
{
for (int i=(pyvalue.Length -1);i> =0;i--)
{
if (pyvalue[i] <=chrasc)
{
returnstr+=pystr[i];
break;
}
}
}
}
return returnstr;
}