同时精通C#和Dephi的朋友帮帮忙吧!
下面两个函数是delphi写的,本人对delphi只懂皮毛,因项目急需,请哪位高手将下面两个函数改成C#,不甚感激!!!,因分不够,等挣到再补。
function HexToInt(HexStr:String):Integer;
var
i,TempInt,LocalInt:Integer;
begin
HexStr:=UpperCase(HexStr);
LocalInt:=1;
Result:=0;
for i:=Length(HexStr) downto 1 do
begin
if HexStr[i] in [ '0 '.. '9 '] then
TempInt:=StrToInt(HexStr[i])
else
TempInt:=Ord(HexStr[i])-Ord( 'A ')+10;
if i=Length(HexStr) then
LocalInt:=1
else
LocalInt:=LocalInt*16;
Result:=Result+TempInt*LocalInt;
end;
end;
function Decode8Bits(s:String):String;
var
i,Len:Integer;
TempStr:String;
begin
Result:= ' ';
Len:=Length(s) Div 2;
for i:=0 to Len-1 do
begin
TempStr:=Copy(s,i*2+1,2);
Result:=Result+Chr(HexToInt(TempStr));
end;
end;
------解决方案--------------------using System;
using System.Globalization;
class Test
{
static int HexToInt(string HexStr)
{
return int.Parse(HexStr, NumberStyles.HexNumber);
}
static string Decode8Bits(string s)
{
string Result = " ";
for (int i = 0; i < s.Length / 2; i++)
{
Result += (char)HexToInt(s.Substring(i, 2));
}
return Result;
}
}