面 试4?ji ji
delphi:
//-------------------------------------------------------
function StrSjisToJis(str: string): string;
var
idx: integer;
flag_ANK: boolean;
begin
{初期値設定}
Result := '';
flag_ANK := True;
idx := 0;
while (idx < Length(str)) do //while string input
//==================================================================================
begin
Inc(idx); // adjust+1
if ByteType(str, idx) = mbLeadByte then
//判断字符串的第一个字符是否是字
begin// 是字
{ANKから2バイトコードへ移行する場合、KIを設定する}
if flag_ANK then
begin
flag_ANK := False;
Result := Result + KI;
end;
{SJIS to JIS変換する}
Result := Result + WordToChar(SjisToJis(CharToWord(str[idx],str[idx + 1])));
Inc(idx);
end
else
begin
{2バイトコードからANKへ移行する場合、KOを設定する}
if not flag_ANK then
begin
flag_ANK := True;
Result := Result + KO;
end;
{ASCIIコードと同一なのでコード変換しない}
Result := Result + str[idx];
end;
end; {while}
{改行時にANKに戻す}
if not flag_ANK then
begin
Result := Result + KO;
end;
end;
zai c# ruhe shixian
thanks!!!!!