// // // // Utf8ToAnsi // // 2010.6.28 // // QQ:52688226 // // // // program Utf2Ansi; {$R *.res} uses SysUtils, Classes; var fi, fo: textfile; // t, s: string; hOutput: THandle; Ts: TStringList; begin if ParamCount <> 2 then begin {$APPTYPE CONSOLE} //SetConsoleTitle('Utf2Ansi 2010.6.26'); //hOutput := GetStdHandle(STD_OUTPUT_HANDLE); //SetConsoleTextAttribute(hOutput, 14); //SetConsoleTextAttribute(hOutput, FOREGROUND_INTENSITY); writeln('使用方法:参数(绝对路径)'); //SetConsoleTextAttribute(hOutput, 13); writeln('<输入Utf8格式文件> <输出Ansi格式文件>'); //SetConsoleTextAttribute(hOutput, 15); writeln('例: Utf2Ansi Utf8.txt Ansi.txt'); readln; //{$APPTYPE CONSOLE} exit; end; Ts := TStringList.Create; assignfile(Fi, ParamStr(1)); reset(fi); assignfile(Fo, 'Buffer'); rewrite(Fo); //s := #239#187#191; //write(fo, s); //readln(fi, S); //if s <> #239#187#191 then begin while not eof(Fi) do begin readln(Fi, S); //writeln(S); //调试 s := utf8toansi(S); //writeln(S); //调试 writeln(Fo, s); end; //--------------------------- closefile(fi); closefile(fo); assignfile(Fi, ParamStr(1)); reset(fi); readln(Fi, S); S := utf8toansi(S); T := StringReplace(s, '?', '', [rfIgnoreCase]); try Ts.LoadFromFile('Buffer'); Ts.Text := StringReplace(Ts.Text, s, t,[rfIgnoreCase]); TS.SaveToFile(ParamStr(2)); finally Ts.Free; closefile(fi); deleteFile('Buffer'); end; end; begin if FileExists(ParamStr(2)) = true then begin Writeln('---------------------'); writeln('Operation Successful!'); Writeln('---------------------') end else begin Writeln('-----------------'); writeln('Operation Failed!'); Writeln('-----------------'); end end end.