function ChName(EnName: string): string;
var
ChLen, pos, len, blen, w, w1, i: integer;
s: string;
begin
result := trim(EnName);
len := length(EnName) - 1;
if (len < 1) or (EnName[1] <> 'V') then
exit;
Delete(EnName, 1, 1);
blen := 0;
pos := 1;
w := 0;
s := '';
while (pos <= len) or (blen > 7) do
begin
while (blen < 8) and (pos <= len) do
begin
w1 := ord(EnName[pos]);
if w1 >= ord('A') then
w1 := w1 - ord('A')
else
w1 := w1 - ord('0') + 26;
w := (w1 shl blen) or w;
inc(pos);
inc(blen, 5);
end;
w1 := w and $FF;
s := chr(w1) + s;
w := w shr 8;
dec(blen, 8);
end;
Result := s;
end;
public class test
{
public string ChName(string EnName)
{
int ChLen, pos, len, blen, w, w1, i;
string s;
string result=EnName.Trim();
len = EnName.Length - 1;
if (len<1 || EnName.Substring(0,1)!="V")
{
return result;
}
EnName = EnName.Substring(1);
blen = 0; pos = 1; w = 0; s = "";
while (blen < 8 && pos <= len)
{
w1 =int.Parse(EnName[pos].ToString());
if (w1>=int.Parse("A")
{
w1-=int.Parse("A");
}
else
{
w1=w1-int.Parse("o")+26;
}
w=(w1<<blen) | w;
pos++;
blen+=5;
}
w1=w & Convert.ToInt32("FF", 16);
s+=w1.ToString();
w=w >> 8;
blen-=8;
result=s;
return result;
}
}
如果能看懂,翻译应该不时什么难事。