How to use Delphi XE's TEncoding to save Cyrillic or ShiftJis text to a file?

If I understand it's pretty simple. Declare an AnsiString with affinity for Cyrillic 1251: type // The code page for ANSI-Cyrillic is 1251 CyrillicString = type AnsiString(1251) Then assign your Unicode string to one of these: var UnicodeText: string; CyrillicText: CyrillicString; .... CyrillicText := UnicodeText You can then write CyrillicText to a stream in the traditional manner: if Length(CyrillicText)>0 then Stream. WriteBuffer(CyrillicText1, Length(CyrillicText)) There should be no BOM for an ANSI encoded text file.

If I understand it's pretty simple. Declare an AnsiString with affinity for Cyrillic 1251: type // The code page for ANSI-Cyrillic is 1251 CyrillicString = type AnsiString(1251); Then assign your Unicode string to one of these: var UnicodeText: string; CyrillicText: CyrillicString; .... CyrillicText := UnicodeText; You can then write CyrillicText to a stream in the traditional manner: if Length(CyrillicText)>0 then Stream. WriteBuffer(CyrillicText1, Length(CyrillicText)); There should be no BOM for an ANSI encoded text file.

Thanks, this is interesting. So basically, I would just save the CyrillicText to the TFileStream without using TEncoding or anything else. What method would you recommend I use to save the string to the TFileStream without loosing any information from the CyrillicString?

– John Riche Jan 28 at 9:11 @John I've edited my question to answer this. – David Heffernan Jan 28 at 9:28.

Not sure what example are you looking for; may be the following can help - the example converts unicode strings (SL) to ANSI Cyrillic: procedure SaveCyrillic(SL: TStrings; Stream: TStream); var CyrillicEncoding: TEncoding; begin CyrillicEncoding := TEncoding. GetEncoding(1251); try SL. SaveToStream(Stream, CyrillicEncoding); finally CyrillicEncoding.

Free; end; end.

Thanks however using that method I must first convert a string to a TStrings first which seems like a big performance hit and that's why I mentioned I extracted the TStrings. SaveToStream method. – John Riche Jan 28 at 9:08.

If I understand it's pretty simple. Declare an AnsiString with affinity for Cyrillic 1251.

Not sure what example are you looking for; may be the following can help - the example converts unicode strings (SL) to ANSI Cyrillic.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions