I found a code in Delphi - See if anyone can help me to convert to vb.net

class function TCM.CRC16( s : string): string;

var

ts,s2 : string;

i,j,code: Integer;

crc,data : word;

HL:string;

HByte:string;

LByte:string;

begin

j := 1;

crc := $ffff;

S2:='';

for i:=1 to length(s) do

begin

if ((copy(s,i,1)>='0') and (copy(s,i,1)<='9'))or((copy(s,i,1)>='a') and (copy(s,i,1)<='f'))

or((copy(s,i,1)>='A') and (copy(s,i,1)<='F')) then

begin

s2:=s2+copy(s,i,1);

end;

end;

S:=S2;

while j<=Length(S) do

begin

while (j<=Length(S)) and (not (S[j] in ['0'..'9','A'..'F','a'..'f'])) do

inc(j);

if (j+1>Length(S))or(not (S[j+1] in ['0'..'9','A'..'F','a'..'f'])) then

ts:='$'+S[j]

else

ts:='$'+S[j]+S[j+1];

Val(ts,data,Code);

inc(j,2);

crc := crc xor data;

for i:=0 to 7 do

if (crc and $01) <> 0 then

crc := (crc shr 1) xor $a001

else crc := crc shr 1;

end;

HL:=inttohex(crc,4);

LByte:=Copy(HL,3,2);

HByte:=Copy(HL,1,2);

Result := LByte+HByte;

end;

class function TCM.CRC16( s : string): string;

var

ts,s2 : string;

i,j,code: Integer;

crc,data : word;

HL:string;

HByte:string;

LByte:string;

begin

j := 1;

crc := $ffff;

S2:='';

for i:=1 to length(s) do

begin

if ((copy(s,i,1)>='0') and (copy(s,i,1)<='9'))or((cop

or((copy(s,i,1)>='A') and (copy(s,i,1)<='F')) then

begin

s2:=s2+copy(s,i,1);

end;

end;

S:=S2;

while j<=Length(S) do

begin

while (j<=Length(S)) and (not (S[j] in ['0'..'9','A'..'F','a'..'f

inc(j);

if (j+1>Length(S))or(not (S[j+1] in ['0'..'9','A'..'F','a'..'f

ts:='$'+S[j]

else

ts:='$'+S[j]+S[j+1];

Val(ts,data,Code);

inc(j,2);

crc := crc xor data;

for i:=0 to 7 do

if (crc and $01) <> 0 then

crc := (crc shr 1) xor $a001

else crc := crc shr 1;

end;

HL:=inttohex(crc,4);

LByte:=Copy(HL,3,2);

HByte:=Copy(HL,1,2);

Result := LByte+HByte;

end;