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. SpringCloud服务负载均衡实现原理02

  2. 最全的测试用例(UI)

    一.文本框为字符型 必填项非空校验:      1.必填项未输入--程序应提示错误:      2.必填项只输入若干个空格,未输入其它字符--程序应提示错误: 字段唯一性校验:(不是所有字段都作此项校 ...

  3. golang 报错illegal rune literal

    记录一下,今天运行一端代码遇到这个报错"illegal rune literal",代码如下: func main() { http.HandleFunc('/login', lo ...

  4. Android : Android Studio 更新至gradle 4.10.1后Variants API变化

    同步警告: WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'v ...

  5. 查询系统正在运行的SQL语句

    查询系统正在运行的SQL语句: select a.program, b.spid, c.sql_text from v$session a, v$process b, v$sqlarea c wher ...

  6. 用canvas画一个房子

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <script t ...

  7. effective java——30使用enum

    1, 枚举太阳系八大行星 package com.enum30.www; public enum Planet {//枚举太阳系八大行星 MERCURY(3.302e+23,2.439e6), VEN ...

  8. python 前端 css

    CSS(Cascading Style Sheet,层叠样式表) 是一种用来表现HTML或XML等文件样式的计算机语言. 作用:是用来美化HTML标签的,相当于给页面化妆. 每个css 都是有两部分组 ...

  9. 德州扑克AI--Programming Poker AI(译)

    前言: 最近在研究德州扑克的AI, 也想由浅入深的看下, 在网上找了一圈, 发现很多文章都提到了一篇文章: Programming Poker AI. 仔细拜读了一下, 觉得非常不错. 这里作下简单的 ...

  10. 链接属性external的使用

    //demo1.c #include<stdio.h> ; //static int x = 10; void print(void) //static void print(void) ...