function StringToFile(mString : string; mFileName : TFileName) : Boolean;
var
vFileChar : file of Char;
I : Integer;
begin
{$I-}
AssignFile(vFileChar , mFileName);
Rewrite(vFileChar);
for I := 1 to Length(mString) do
Write(vFileChar , mString[I]);
CloseFile(vFileChar);
{$I+}
Result := (IOResult = 0) and (mFileName <> '');
end;

function FileToString(mFileName : TFileName) : string;
var
vFileChar : file of Char;
vChar : Char;
begin
Result := '';
{$I-}
AssignFile(vFileChar , mFileName);
Reset(vFileChar);
while not Eof(vFileChar) do
begin
Read(vFileChar , vChar);
Result := Result + vChar;
end;
CloseFile(vFileChar);
{$I+}
end;

function StreamToString(mStream : TStream) : string;
var
I : Integer;
begin
Result := '';
if not Assigned(mStream) then Exit;
SetLength(Result , mStream.Size);
for I := 0 to Pred(mStream.Size) do
try
mStream.Position := I;
mStream.Read(Result[Succ(I)] , 1);
except
Result := '';
end;
end;

function StringToStream(mString : string; mStream : TStream) : Boolean;
var
I : Integer;
begin
Result := True;
try
mStream.Size := 0;
mStream.Position := 0;
for I := 1 to Length(mString) do
mStream.Write(mString[I] , 1);
except
Result := False;
end;
end;

delphi 字符串string转流TStream的更多相关文章

  1. 【stanford C++】字符串(String)与流(Stream)

    字符串(String)与流(Stream) 一.C++中字符串(String) 字符串(String):就是(可能是空的)字符序列. C++中的字符串在概念上和Java中的字符串类似. C++字符串用 ...

  2. C# 字符串string和内存流MemoryStream及比特数组byte[]之间相互转换

    定义string变量为str,内存流变量为ms,比特数组为bt 1.字符串转比特数组 复制代码 代码如下: (1)byte[] bt=System.Text.Encoding.Default.GetB ...

  3. 字符串string和内存流MemoryStream及比特数组byte[]互转

    原文:字符串string和内存流MemoryStream及比特数组byte[]互转   字符串string和内存流MemoryStream及比特数组byte[]互转比较 定义string变量为str, ...

  4. c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换

    字节数组byte[]与图片image之间的转化 字节数组转换成图片 public static Image byte2img(byte[] buffer) { MemoryStream ms = ne ...

  5. delphi字符串函数大全

    转帖:delphi字符串函数大全 2009-11-17 16:43:55 分类: delphi字符串函数大全 ━━━━━━━━━━━━━━━━━━━━━首部 function StringToGUID ...

  6. Delphi中String类型原理介绍

    Delphi中字符串的操作很简单,但幕后情况却相当复杂.Pascal传统的字符串操作方法与Windows不同,Windows吸取了C语言的字符串操作方法.32位Delphi中增加了长字符串类型,该类型 ...

  7. Delphi字符串、PChar与字符数组之间的转换

    来自:http://my.oschina.net/kavensu/blog/193719 ------------------------------------------------------- ...

  8. 汉字与区位码互转(天天使用Delphi的String存储的是内码,Windows记事本存储的文件也是内码),几个常见汉字的各种编码,utf8与unicode的编码在线查询,附有读书笔记 good

    汉=BABA(内码)=-A0A0=2626(区位码)字=D7D6(内码)=-A0A0=5554(区位码) 各种编码查询表:http://bm.kdd.cc/ 汉(记住它,以后碰到内存里的数值,就会有敏 ...

  9. delphi字符串分隔函数用法实例

    这篇文章主要介绍了delphi字符串分隔函数用法,通过自定义函数SeparateTerms2实现将字符串分割后存入字符串列表的功能,具有一定的实用价值,需要的朋友可以参考下 本文实例讲述了delphi ...

随机推荐

  1. 命令行听歌http://www.linuxsir.org/bbs/thread280142.html?pageon=1#1584689

    在纯字符界面下听歌 利用 play 命令可以在命令行中播放音频文件,在纯字符界面下也没问题! ----------------------------------------------------- ...

  2. hibernate操作mysql插入修改中文出现乱码

    第一步:mysql的安装目录下配置文件my.ini里面的所有default-character-set改成default-character-set = utf8: 第二部:建立数据库时候字符集选项选

  3. mariadb安装和一些sql基础

    MariaDB安装    yum -y install mariadb mariadb-server 启动    systemctl start mariadb     systemctl enabl ...

  4. effective java——31用实例域代替序数

    1,永远不要根据枚举的序数导出与它关联的值,而是要将他保存在一个实例域中.(ordinal()) public enum Ensemble { SOLO, DUET, TRIO, QUARTET, Q ...

  5. vue学习笔记 - 篇2

    1.借助Vue.extend()方法创建组件 注意点 var Aaa = Vue.extend({ template: "<h1>这是标题</h1>" }) ...

  6. 一条命令将windows下多个ts文件合并为一个ts文件

    首先在待合并的文件夹下创建concat.bat(名字随意啦),写入如下命令 copy /b "%~dp0"\*.ts "%~dp0"\new.ts 执行该命令后 ...

  7. PHP发送POST请求

    方式一:cURL $url = "localhost/test/post/service.php"; $data = array("a"=>"网 ...

  8. 《DSP using MATLAB》Problem 7.6

    代码: 子函数ampl_res function [Hr,w,P,L] = ampl_res(h); % % function [Hr,w,P,L] = Ampl_res(h) % Computes ...

  9. if 循环

    age_of_princal = 56guess_age = int(input(">>:")) if guess_age == age_of_princal: pri ...

  10. CodeForce 517 Div 2. B Curiosity Has No Limits

    http://codeforces.com/contest/1072/problem/B B. Curiosity Has No Limits time limit per test 1 second ...