码迷,mamicode.com
首页 > 其他好文 > 详细

Strem String

时间:2015-04-21 12:42:47      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

一、TStringStream方法

Strem>String

TMemoryStream to String

stm: TStream;

ss: TStringStream;

 

image.picture.savetoStream(stm);

ss := TStringStream.Create(‘‘, TEncoding.Unicode);

ss.CopyFrom(stm, 0);
str := ss.DataString;

stm.Free;
ss.Free;

String>Strem

stm: TStream;
ss: TStringStream;

stm := TMemoryStream.Create;
ss := TStringStream.Create(‘‘, TEncoding.Unicode);

ss.WriteString(str);

ss.Position := 0;

stm.CopyFrom(ss, ss.Size);

stm.Position := 0;

 

二、TBytes和stringof转换

Strem>String

  abyte: TBytes;

SetLength(abyte, stm.Size);
stm.Read(abyte, stm.Size);
str := stringof(abyte);

 

String>Strem

abyte := BytesOf(gstr);
stm.Write(abyte, Length(abyte));

stm.Position := 0;
img.picture.LoadFromStream(stm);

 

 

function BytesOf(const Val: UnicodeString): TBytes;
begin
Result := TEncoding.Default.GetBytes(Val);
end;

 

function StringOf(const Bytes: TBytes): UnicodeString;
begin
if Assigned(Bytes) then
Result := TEncoding.Default.GetString(Bytes, Low(Bytes), High(Bytes) + 1)
else
Result := ‘‘;
end;

Strem String

标签:

原文地址:http://www.cnblogs.com/cb168/p/4443814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!