W WRainbug! Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-15 #1 请问怎么把widestring直接保存成文件? 谢谢.
M _Murray Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-15 #2 procedure TForm1.Button1Click(Sender: TObject); var aa : widestring; st : tstringlist; begin aa := 'adsfasdfasdfasdfasdfasdf'; st := tstringlist.Create; st.Add(aa); st.SaveToFile('c:/aa.txt'); st.free; end;
procedure TForm1.Button1Click(Sender: TObject); var aa : widestring; st : tstringlist; begin aa := 'adsfasdfasdfasdfasdfasdf'; st := tstringlist.Create; st.Add(aa); st.SaveToFile('c:/aa.txt'); st.free; end;
W WRainbug! Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-16 #5 to LSUPER: 我就是问AnsiToUtf8转换后怎么保存, tstringlist是ansi的. 用_Murray说的方法, 保存出来还是ansi. 请教怎么把转换后的string, 直接保存成unicode编码的文件. 谢谢.
to LSUPER: 我就是问AnsiToUtf8转换后怎么保存, tstringlist是ansi的. 用_Murray说的方法, 保存出来还是ansi. 请教怎么把转换后的string, 直接保存成unicode编码的文件. 谢谢.
S shangshang Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-16 #6 试试:我用流了一下 procedure TForm1.Button1Click(Sender: TObject); const fn='c:/test.txt'; var ws:WideString; m:TFileStream; begin ws:='hello,哥们'; m:=TFileStream.Create(fn,fmOpenWrite); m.WriteBuffer(ws[1],Length(ws)*2); m.free; end;
试试:我用流了一下 procedure TForm1.Button1Click(Sender: TObject); const fn='c:/test.txt'; var ws:WideString; m:TFileStream; begin ws:='hello,哥们'; m:=TFileStream.Create(fn,fmOpenWrite); m.WriteBuffer(ws[1],Length(ws)*2); m.free; end;
A Avalon Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-16 #8 抄的 -----把那段unicode文本前加了两个字节(#$feff),然后用二进制的方式存为文件 试试看! 原贴见 http://www.delphibbs.com/delphibbs/dispq.asp?lid=435596
抄的 -----把那段unicode文本前加了两个字节(#$feff),然后用二进制的方式存为文件 试试看! 原贴见 http://www.delphibbs.com/delphibbs/dispq.asp?lid=435596
N newmoonfaw Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-16 #9 写入文件: var UStr:UTF8String; Fname:string; m:TMemoryStream; begin UStr:=AnsiToUtf8(memo1.Text ); FName:='c:/1.txt'; m:=TMemoryStream.Create; m.WriteBuffer(UStr[1],Length(UStr)*2); m.SaveToFile('c:/1.txt'); end; 从文件中读出: var UStr:UTF8String; str:string; begin memo1.Lines.LoadFromFile('c:/1.txt'); str:=Utf8decode(memo1.Text ); memo1.Text :=str; end;
写入文件: var UStr:UTF8String; Fname:string; m:TMemoryStream; begin UStr:=AnsiToUtf8(memo1.Text ); FName:='c:/1.txt'; m:=TMemoryStream.Create; m.WriteBuffer(UStr[1],Length(UStr)*2); m.SaveToFile('c:/1.txt'); end; 从文件中读出: var UStr:UTF8String; str:string; begin memo1.Lines.LoadFromFile('c:/1.txt'); str:=Utf8decode(memo1.Text ); memo1.Text :=str; end;