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. QChart绘制折线区域

    效果图: 代码: // 创建折线上点的序列 QLineSeries *splineSeries = new QLineSeries(); //QSplineSeries *splineSeries = ...

  2. gdb pretty printer for STL debug in Linux

    Check your gcc version. If it is less than 4.7, you need use another printer.py file. Get the file f ...

  3. learning makefile static model

  4. API的控制器

    // GET: api/showApi /// <summary> /// 显示 查询 /// </summary> /// <param name="name ...

  5. 5.使用std的迭代器访问并修改图像

    void Test_ColorReduceByIterator() { Mat g_srcImage=imread("D:\\OpenCV Projects\\OpenCV_Test_Ima ...

  6. 类的构造器-init和new

    提到构造器,大家都会想到 __init__,那么__new__是什么?也是构造器. init 构造器 都很熟悉了,直接上代码 class MyClass(object): def __init__(s ...

  7. 2018 ICPC 区域赛 焦作场 D. Keiichi Tsuchiya the Drift King(计算几何)

    http://codeforces.com/gym/102028/problem/D 题意:根据题中给的那个图,然后题目给你 a,b,r,d,让你求出最小的满足矩形通过弯道的w 思路:

  8. day 06 字符串和列表的方法

    一.整形int 定义方式: age=18    #调用age=int(18)的方法,自动调用 n=int("123") #只能转换纯数字类型 二:浮点型float 定义方式 sal ...

  9. python day27--常用模块 time,random,os,序列化

    一.time模块 %y 两位数的年份表示(00-99) %Y 四位数的年份表示(000-9999) %m 月份(01-12) %d 月内中的一天(0-31) %H 24小时制小时数(0-23) %I ...

  10. 读txt文件乱码

    /** * 读入TXT文件 */public static List<String> readFile(String pathName) {// 绝对路径或相对路径都可以,写入文件时演示相 ...