1. 数据类型转化

1.1.         数值和字符串转化

Procedure Str(X [: Width [ : Decimals ]]; var S);

将数值X按照一定格式转化成字符串S。Width指定S的总长度,Decimals指定小数点后的位数。

EX: Str(12.2 : 6 : 2 , S); //S=’  12.20’;

Procedure Val(S ; Var V; var Code : Integer);

将字符串S转化为数值V。如果不能转化,则Code返回第一个非法字符的位置。

EX: Val(’12.00’ , V , Code); //Code返回’.’的位置3;

1.2.         整数和字符串转化

Function IntToStr(Value : Integer) : String ;overload;

Function IntToStr(Value : Int64) : String ;overload;

第一个用于32Bit整数,第二个用于64Bit整数。

Function StrToInt(const S : String) : Integer;

Function StrToInt64(const S : String) : Int64;

如果S包含非数字字符,则产生异常,但是S可以是十六进制表示方法,如$A,则返回10。

Function StrToIntDef(const S : String; Default : Integer): Integer;

Function StrToInt64Def(const S : string; Default : Int64):Int64;

如果S非法,则返回Default指定的默认值,不产生异常。

Function TryStrToInt(const S : String; out Value : Integer) : Boolean;

Function TryStrToInt64(const S : String; out Value : Int64) : Boolean;

转化得到的整数保存在输出参数Value中,不能转化则返回false。

Function IntToHex(Value : Integer; Digits : Integer) : String ; overload;

Function IntToHex(Value : Int64; Digits : Integer) : String ; overload;

将十进制整数转化成二进制整数,结果用字符串表示。

Function HexToBin(Text , Buffer : PChar; BufSize : Integer) : Integer;

将十六进制整数转化成二进制,结果用字符串表示,保存在Buffer中。

1.3.         实数和字符串转化

Function FloatToStr(Value : Extended) : String;

Function CurrToStr(Value : Currency) : String;

Function FloatToStrF(Value : Extended; Format : TFloatFormat; Precision, Digits : Integer) : String;

Function FormatFloat(const Format : String; Value : Extended) : String;

Function FloatToText(Buffer : PChar; const Value; ValueType : TFloatValue; Format : TFloatFormat; Precision, Digits : Integer) : Integer;

Function CurrToStrF(Value : Currency; Format : TFloatFormt; Digits : Integer) : String;

Function FormatCurr(const Format : String; Value : Currency) : String;

指定格式。

Function StrToFloat(const S : String) : Extended;

Function StrToCurr(const S : String) : Currency;

字符串转化为实数。

另外:StrToFloatDef , StrToCurrDef , TryStrToFloat , TryStrToCurr

1.4.         实数子类型相互转化

Function FloatToCurr(const Value : Extended) : Currency;

1.5.         布尔类型和字符串转化

Function StrToBool(const S : String) : Boolean;

Function BoolToStr(B : Boolean; UseBoolStrs : Boolean = False) : String;

  1. 字符串处理

2.1字符串常用过程及函数

字符串的索引是从1开始

Function Length(S) : Integer;

Procedure SetLength(var S; NewLength : Integer);

Procedure SetString(var S : String; buffer :PChar; len : Integer);

设置一个字符串的内容(从buffer复制)和长度。

Function Pos(Substr : String; S : String) : Integer;

取得字符串起始位置

Function StringOfChar(Ch : Char; Count : Integer) : String;

用Count个Ch合成一个字符串。

Function DupeString(const AText : String; ACount : Integer) : String;

用ACount个AText合成一个字符串。

Function Concat(s1 [, s2 , … , sn] : String) : String;

Procedure Insert(Source : String; var S : String; Index : Integer);

Function Copy(S; Index, Count : Integer) : String;

Function StringReplace(const S, OldPattern, NewPattern : String; Flags : TReplaceFlags) : String;

用NwePattern替换S中的子字符串OldPattern。

Procedure Delete(var S : String; Index, Count : Integer);

Procedure UniqueString(var str : String); overload;

Porcedure UniqueString(var str : WideString); overload;

指定字符串只有一个引用。

Function WrapText(const Text, BreakStr : String; nBreakChars : TSysCharSet; MaxCol : Integer) : String; overload;

Function WrapText(const Text : String, MaxCol : Integer =45) : String; overload;

分割一个字符串。MaxCol表示一行的最大长度,BreakStr表示在每行末尾要插入的分隔符,如果使用第二种格式,则插入回车换行符。它遇到nBreakChars某字符就分割一次,如果使用第二种格式,则检查空格、连字符、跳格符。

Function QuotedStr(const S : String) : String;

用单引号将字符串包裹起来。字符串中的引号会被自动处理。

Function LastDelimiter(const Delimiters, S : String) : Integer;

Delimiters是多个字符的组合,它返回某个字符在S中最后出现的位置。

Function IsDelimiter(const Delimiters, S : String; Index : Integer) : Boolean;

Function CompareStr(const S1, S2 : String) : Integer;

比较两个字符串,区分大小写。

Function SameText(const S1, S2 : String) : Boolean;

Function CompareText(const S1, S2 : String) : Integer;

不区分大小写。

Function LeftStr(const AText : String; ACount : Integer) : String;

取左边部分字符串。

Function RightStr(const AText : String; ACount : Integer) : String;

Function LowerCase(const S : String) : String;

Function UpperCase(const S : String) : String;

Function MidStr(const AText : String; const AStart : Integer) : String;

取得部分字符串,等价于Copy。

Function ReverseString(const AText : String) : string;

翻转字符串。

Procedure Str(X [ : Width [ : Decimals ]];  var S);

格式化一个字符串并保存到S。

Function Trim(const S : String) : String; overload;

Function Trim(const S : WideString) : WideString; overload;

去掉字符串头尾的空格和控制字符。

2.2 和字符串相关的类TStrings

TStrings是字符串列表对象的基类,是一个抽象类。

重要属性:

Property CommaText : String;

按照system data format格式,在字符串列表和字符串之间转换。

字符串列表->字符串:

所有字符串被逗号分割;

如果字符串中包含空格、逗号、双引号,则该字符串头尾会加上双引号;

字符串中的双引号被自动重复。

字符串->字符串列表:

不在双引号中的空格、逗号是分隔符;

连续的逗号分隔符会生成空字符串;

逗号分隔符前后的空格分隔符不作为分隔符,被忽略。

Property DelimitedText : String;

Property Delimiter : Char;

Property QuoteChar : Char;

按照Delimiter和QuoteChar在字符列表和字符串之间转换。当Delimiter为逗号,QuoteChar是双引号时,DelimitedText和CommaText完全一样。

Property Text : String;

在列表各项的末尾加上回车换行符进行字符串列表和字符串之间的转换。

Property Name[Index : Integer] : String;

当列表中字符串是”Name=Name”格式时,得到Name。只读属性。

Property Value[const Name : String] : String;

当列表中字符串时”Name=Value”格式时,得到Value。

Property String[Index : Integer] : String; default;

引用第Index项字符串。

Property Object[Index : Integer] : TObject;

引用第Index项字符串关联的对象。

重点方法:

Function AddObject(const S : String; AObject : TObject) : Integer; virtual;

将一个具有关联对象的字符串增加到列表项,返回其放置的位置。

Procedure AddStrings(Strings : TStrings); virtual;

增加一个字符串列表的所有字符串到末尾。

Function Equals(Strings : TStrings) : Boolean;

比较两个列表,不比较字符串关联的对象。

Procedure Exchange(Index1, Index2 : Integer); virtual;

交换两个项的位置。

Procedure LoadFromFile(const FileName : String); virtual;

Procedure SaveToFile(const FileName : String); virtual;

从文件读取/保存列表项,文件中每行对应列表中每项。

Procedure LoadFromStream(Stream : TStream); virtual;

Procedure SaveToStream(Stream : TStream); virtual;

将流读到Text属性/保存到流,然后转化为列表项。回车符或换行符或二者任意组合作为分割符。

Procedure Move(CurIndex, NewIndex : Integer); virtual;

将CurIndex处列表项移到NewIndex处。

2.3 TStringList

TStringList是TStrings的直接子类。它实现了TStrings的所有抽象方法。

重要属性:

Property CaseSensitive : Boolean;

是否区分大小写。

Property Sorted : Boolean;

是否对列表排序,默认是false。为True时按升序排列。

Property Duplicates : TDuplicates;

当列表被升序排列(包括按升序插入、Sorted=True 或者调用Sort 方法等)后,用户试图插入和已有列表项重复的字符串时作何处理。

Type TDuplicates = ( dupIgnore , dupAccept , dupError );

分别是不能插入、允许插入、不能插入且触发异常。

重点方法:

Procedure Sort ; virtual;

将列表项按升序排列。

Function Find(const S : string; var Index : Integer) : Boolean ; virtual;

当列表被升序排列(包括按升序插入、Sorted=True 或者调用Sort 方法等,在非升序状态下,该方法总是返回False)后,查找S 在列表中是否存在,Index 返回位置。一般不使用这个方法,而使用IndexOf。

procedure CustomSort(Compare: TStringListSortCompare); virtual;

type TStringListSortCompare = function(List : TStringList; Index1, Index2 : Integer) : Integer;

自定义排序方法。规则如下:如果Index1 处字符串应该在Index2 之前,应返回负数;如果相等,应返回0;如果应该在Index2 之后,应返回正数。

两个事件:

Property OnChange : TNotifyEvent;

Property OnChanging : TNotifyEvent;

列表变化后/前触发。

delphi常用函数过程的更多相关文章

  1. (转载)delphi 常用函数(数学)

    delphi 常用函数(数学) Delphi中怎么将实数取整? floor 和 ceil 是 math unit 里的函数,使用前要先 Uses Math.trunc 和 round 是 system ...

  2. Delphi 常用函数(数学函数)round、trunc、ceil和floor

    源:Delphi 常用函数(数学函数)round.trunc.ceil和floor Delphi 常用函数(数学) Delphi中怎么将实数取整? floor 和 ceil 是 math unit 里 ...

  3. NotePad++ delphi/Pascal函数过程列表插件

    从cnpack上爬下来的 函数过程列表 点击下载

  4. 自己写的一些Delphi常用函数

    今天在整理以前写过的代码,发现有些函数还是挺实用的,决定将其贴到Blog上,与众多好友一起分享.{*************************************************** ...

  5. delphi常用函数

    直接引用了 http://www.cnblogs.com/doit8791/archive/2012/05/17/2507073.html.

  6. Delphi 常用函数记录

    //判断是否是数字 function IsNumeric(sDestStr: string): Boolean; //简写多余汉字 function SimplifyWord(sWord: strin ...

  7. delphi常用函数和方法

     uses ShellApi, ActiveX, ComObj, ShlObj; function HasText(Text: string; const Values: array of strin ...

  8. Delphi 常用API 函数

    Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小 AnyPopup 判断屏幕上是否存在任何弹出式窗口 ArrangeIconic ...

  9. Delphi 常用API 函数列表

    Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小AnyPopup 判断屏幕上是否存在任何弹出式窗口ArrangeIconicWi ...

随机推荐

  1. 【转】特殊权限控制之SUID、SGID、Sticky

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://soysauce93.blog.51cto.com/7589461/1715583 ...

  2. php dirname(__FILE__) 获取当前文件的绝对路径

    dirname(__FILE__) 取到的是当前文件的绝对路径,也就是说,比起相对路径,查找速度是最快的. 比如当前文件是放在(d:\www\)下,文件名是test.php.  测试的代码如下: &l ...

  3. C# 学习的随笔【随时更新】

    1.结束自己 Application.Exit(); //这个东西有重载函数

  4. Drupal8开发教程:模块开发——创建新页面

    之前我们已经通过<Drupal8开发教程:认识.info.yml文件>对模块的YAML文件有了了解,今天我们来看如何通过模块开发的方式添加一个新的页面. 在 Drupal 7 中,通过模块 ...

  5. 洛谷P2723 丑数 Humble Numbers

    P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...

  6. NULL值比较,两个列的合并,列值按条件替换。

    show create table 表名 -- 显示创建表的sql语句. 为已有的表增加新列.alter table 表名 add 列名 int NULL -- 此行加了一个int 类型 默认可以nu ...

  7. js 打开PDF

    用插件打开PDF的一个超连接 但是谷歌了很久 ,发现了一个很好的方法 就是借google 来打开一个PDF ,而不下载PDF: _yourID.setAttribute('onclick'," ...

  8. linux 内存使用

    # df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 1.9G 45G 5% / tmpfs 1.9G 0 1.9G 0% ...

  9. 【MySQL】MySQL无基础学习和入门之一:数据库基础概述和实验环境搭建

    数据库基础概述  大部分互联网公司都选择MySQL作为业务数据存储数据库,除了MySQL目前还有很多公司使用Oracle(甲骨文).SQLserver(微软).MongoDB等. 从使用成本来区分可以 ...

  10. 快速搭建 Node.js 开发环境以及加速 npm

    如何快速搭建 node 开发环境 npm 超慢 github 无法打开的问题 于是我觉得应该写一篇文章解答所有这些起步问题,让新同学也能顺顺利利入门. 快速搭建 Node.js 开发环境 如果你想长期 ...