首页 > 编程语言 >软件的基本是要处理好”算法“及其基础(三)delphi 10.4.1字符串工具单元及其函数

软件的基本是要处理好”算法“及其基础(三)delphi 10.4.1字符串工具单元及其函数

时间:2023-01-23 09:44:20浏览次数:56  
标签:function const 10.4 delphi overload Integer AText 及其 string

  //:关于字符串的定义:
  _RawByteStr = RawByteString;
  {$IFDEF NEXTGEN}
    UTF8String = type _AnsiString(65001);
    RawByteString = type _AnsiString($ffff);  //:$ffff=  65535
    {$NODEFINE UTF8String}
    {$NODEFINE RawByteString}
  {$ELSEIF Defined(LINUX64) or Defined(OSX64) or Defined(ANDROID)}
    UTF8String = type AnsiString(65001);
    RawByteString = type AnsiString($ffff);  //:$ffff=  65535
    {$NODEFINE UTF8String}
    {$NODEFINE RawByteString}
  {$ELSE}
    UTF8String = type AnsiString(65001);
    RawByteString = type AnsiString($ffff);  //:$ffff=  65535
  {$ENDIF}
    PUTF8String = ^UTF8String;
    PRawByteString = ^RawByteString;
  {$IF Defined(NEXTGEN) or Defined(LINUX64) or Defined(OSX64) or Defined(ANDROID)}
    {$NODEFINE PUTF8String}
    {$NODEFINE PRawByteString}
  {$ENDIF NEXTGEN or LINUX64 or OSX64 or ANDROID}

 

你可能不常用的字符串函数:delphi.System.StrUtils.pas字符串工具单元中的函数

unit System.StrUtils;
 
interface
 
{$IFDEF CPUX86}
 
{$DEFINE X86ASM}
 
{$ELSE !CPUX86}
 
{$DEFINE PUREPASCAL}
 
{$ENDIF !CPUX86}
 
{$HPPEMIT LEGACYHPP}
 
uses
 
System.Types, System.SysUtils;
 
{$WARN WIDECHAR_REDUCED OFF}
 
{如果两个字符串相似(使用Soundex算法或相似的东西),则AnsiResemblesText返回true}
 
function ResemblesText(const AText, AOther: string): Boolean; overload; function AnsiResemblesText(const AText, AOther: string): Boolean; overload;
 
{如果在给定文本中找到子文本(不区分大小写),则AnsiContainsText返回true}
 
function ContainsText(const AText, ASubText: string): Boolean; inline; overload; function AnsiContainsText(const AText, ASubText: string): Boolean; overload;
 
{如果给定文本的开头或结尾部分与子文本匹配,且不区分大小写,则AnsiStartsText和AnsiEndText返回true}
 
function StartsText(const ASubText, AText: string): Boolean; inline; overload; function AnsiStartsText(const ASubText, AText: string): Boolean; overload;
 
function EndsText(const ASubText, AText: string): Boolean; inline; overload; function AnsiEndsText(const ASubText, AText: string): Boolean; inline; overload;
 
{AnsiReplaceText会在不区分大小写的情况下用另一个子字符串替换所有出现的子字符串(不支持递归子字符串替换)}
 
function ReplaceText(const AText, AFromText, AToText: string): string; inline; overload; function AnsiReplaceText(const AText, AFromText, AToText: string): string; overload; { AnsiMatchText & AnsiIndexText provide case like function for dealing with strings }
 
function MatchText(const AText: string; const AValues: array of string): Boolean; overload;
 
function AnsiMatchText(const AText: string; const AValues: array of string): Boolean; overload;
 
function IndexText(const AText: string; const AValues: array of string): Integer; overload;
 
function AnsiIndexText(const AText: string; const AValues: array of string): Integer; overload;
 
{这些功能与上述功能类似,但区分大小写}
 
function ContainsStr(const AText, ASubText: string): Boolean; inline; overload;
 
function AnsiContainsStr(const AText, ASubText: string): Boolean; overload;
 
function StartsStr(const ASubText, AText: string): Boolean; inline; overload;
 
function AnsiStartsStr(const ASubText, AText: string): Boolean; overload;
 
function EndsStr(const ASubText, AText: string): Boolean; inline; overload;
 
function AnsiEndsStr(const ASubText, AText: string): Boolean; overload;
 
function ReplaceStr(const AText, AFromText, AToText: string): string; inline; overload;
 
function AnsiReplaceStr(const AText, AFromText, AToText: string): string; overload;
 
function MatchStr(const AText: string; const AValues: array of string): Boolean; overload;
 
function AnsiMatchStr(const AText: string; const AValues: array of string): Boolean; overload;
 
function IndexStr(const AText: string; const AValues: array of string): Integer; overload;
 
function AnsiIndexStr(const AText: string; const AValues: array of string): Integer; overload;
 
{DupeString将返回给定字符串的N个副本}
 
function DupeString(const AText: string; ACount: Integer): string; overload;
 
{ReverseString简单地反转给定的字符串}
 
function ReverseString(const AText: string): string; overload;
 
function AnsiReverseString(const AText: string): string; overload;
 
{StuffString用另一个替换字符串的一部分}
 
function StuffString(const AText: string; AStart, ALength: Cardinal;
 
const ASubText: string): string; overload;
 
{RandomFrom将随机返回给定的字符串之一}
 
function RandomFrom(const AValues: array of string): string; overload;
 
{如果传入的值为true,IfIfn将返回真字符串,否则将返回假字符串}
 
function IfThen(AValue: Boolean; const ATrue: string; AFalse: string = ''): string; overload; inline;
 
{SplitString将字符串拆分为由指定的分隔符分隔的不同部分}
 
function SplitString(const S, Delimiters: string): TStringDynArray;
 
{类似基本功能/左,右,中}
 
{$IFNDEF NEXTGEN}
 
function LeftStr(const AText: AnsiString; const ACount: Integer): AnsiString; overload; deprecated 'Moved to the AnsiStrings unit';
 
function RightStr(const AText: AnsiString; const ACount: Integer): AnsiString; overload; deprecated 'Moved to the AnsiStrings unit';
 
function MidStr(const AText: AnsiString; const AStart, ACount: Integer): AnsiString; overload; deprecated 'Moved to the AnsiStrings unit';
 
{类似基本功能/ LeftB,RightB,MidB这些功能不在乎语言环境信息。}
 
function LeftBStr(const AText: AnsiString; const AByteCount: Integer): AnsiString; deprecated 'Moved to the AnsiStrings unit';
 
function RightBStr(const AText: AnsiString; const AByteCount: Integer): AnsiString; deprecated 'Moved to the AnsiStrings unit';
 
function MidBStr(const AText: AnsiString; const AByteStart, AByteCount: Integer): AnsiString; deprecated 'Moved to the AnsiStrings unit';
 
{$ENDIF !NEXTGEN}
 
function LeftStr(const AText: string; const ACount: Integer): string; overload;
 
function RightStr(const AText: string; const ACount: Integer): string; overload;
 
function MidStr(const AText: string; const AStart, ACount: Integer): string; overload;
 
{类基本函数/ Delphi样式函数名称}
 
function AnsiLeftStr(const AText: string; const ACount: Integer): string; overload;
 
function AnsiRightStr(const AText: string; const ACount: Integer): string; overload;
 
function AnsiMidStr(const AText: string; const AStart, ACount: Integer): string; overload;
 
type
 
TStringSeachOption = (soDown, soMatchCase, soWholeWord);
 
TStringSearchOptions = set of TStringSeachOption;
 
{SearchBuf是用于任意文本缓冲区的搜索例程。如果找到匹配项,该函数将返回一个指向缓冲区中匹配字符串开头的指针。如果找不到匹配项,则该函数返回nil。如果指定了soDown,则执行正向搜索,否则功能将向后搜索文本。使用SelStart和SelLength跳过“选定的”文本;这将导致搜索在指定文本之前(soDown)之前或之后开始。}
 
const
 
{默认字定界符是除核心字母数字外的任何字符。}
 
WordDelimiters: set of Byte = [0..255] - [Ord('a')..Ord('z'), Ord('A')..Ord('Z'), Ord('1')..Ord('9'), Ord('0')];
 
{$IFNDEF NEXTGEN}
 
function SearchBuf(Buf: PAnsiChar; BufLen: Integer; SelStart, SelLength: Integer; SearchString: AnsiString; Options: TStringSearchOptions = [soDown]): PAnsiChar; overload; deprecated 'Moved to the AnsiStrings unit';
 
{$ENDIF}
 
{$IFDEF UNICODE}
 
function SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength: Integer; SearchString: String; Options: TStringSearchOptions = [soDown]): PChar; overload;
 
{$ENDIF}
 
{PosEx在S中搜索SubStr,如果找到则返回SubStr的索引位置,否则返回0。如果未给出“偏移”,则结果与调用位置相同。如果指定了“偏移”并且> 1,则搜索从S内的“偏移”位置开始。如果“偏移”大于“长度(S)”,则PosEx返回0。默认情况下,“偏移”等于1。
function PosEx(const SubStr, S: string; Offset: Integer = 1): Integer; inline; overload;
{Soundex函数返回给定字符串的Soundex代码。与原始的Soundex例程不同,此函数可以返回不同长度的代码。此功能大致基于John Midwinter编写的SoundBts。有关Soundex的更多信息,请访问:http://www.nara.gov/genealogy/coding.html此功能背后的一般理论最早于1918年获得专利(US1261167和US1435663),但现在已在公共领域。注意:此功能不会尝试处理“带前缀的名称”的问题。}
 
type
 
TSoundexLength = 1..MaxInt;
 
function Soundex(const AText: string; ALength: TSoundexLength = 4): string;
 
{SoundexInt使用Soundex,但返回编码为整数的结果Soundex代码。但是,由于整数大小的限制,此功能仅限于八个字符或更少的Soundex代码。DecodeSoundexInt旨在将SoundexInt的结果解码回普通的Soundex代码。长度不是必需的,因为它已编码为SoundexInt的结果。}
 
type
 
TSoundexIntLength = 1..8;
 
function SoundexInt(const AText: string; ALength: TSoundexIntLength = 4): Integer;
 
function DecodeSoundexInt(AValue: Integer): string;
 
{SoundexWord是SoundexInt的特殊情况版本,它返回编码成单词的Soundex代码。但是,由于单词大小的限制,此功能使用四个字符的Soundex代码。DecodeSoundexWord旨在将SoundexWord的结果解码回普通的Soundex代码。}
 
function SoundexWord(const AText: string): Word;
 
function DecodeSoundexWord(AValue: Word): string;
 
{SoundexSimilar和SoundexCompare是使用Soundex编码功能的简单比较功能。}
 
function SoundexSimilar(const AText, AOther: string; ALength: TSoundexLength = 4): Boolean;
 
function SoundexCompare(const AText, AOther: string; ALength: TSoundexLength = 4): Integer;
 
{AnsiResemblesText的默认入口点}
 
function SoundexProc(const AText, AOther: string): Boolean;
 
type
 
TCompareTextProc = function(const AText, AOther: string): Boolean;
 
{如果AnsiResemblesText的默认行为(使用Soundex)不适合您的情况,则可以将其重定向到您自己选择的函数}
 
 
var
  ResemblesProc: TCompareTextProc = SoundexProc;
  AnsiResemblesProc: TCompareTextProc = SoundexProc;
 

 

标签:function,const,10.4,delphi,overload,Integer,AText,及其,string
From: https://www.cnblogs.com/xionda/p/17065006.html

相关文章

  • TCP粘包拆包、原因及其解决方式
    问题表现TCP是一个流协议,其字节流没有明确的分界线。TCP底层并不了解上层数据的具体含义,它会根据TCP缓冲区的实际情况进行包的划分,一个完整的包可能会被TCP拆分成多个包......
  • 折腾delphi2009
    很老的软件了,几年前修改象棋演播室时用到过。重装机器后一直没装这个软件。前几天从网上重新下载了安装包,根据说明安装,解密,似乎一切顺利。但是第二次启动时,提示无法在临时......
  • 【最新】Delphi XE7 绿色版下载,亲测可用!
    最后更新时间2017-12-05.本文整理自2ccc盒子iny的帖子→链接到原贴破解→链接一、绿色版介绍绿色版除了不包含FastReport(RADStudio自带的FastReport为精简......
  • 功能测试必备:Fiddler 弱网测试及其测试思路归纳总结
    大家好啊,我是大田之前介绍了一篇使用Charles做弱网测试:功能测试必备:抓包工具Charles弱网测试,本篇来看看Fiddler如何做弱网测试。弱网本质是访问速度特别慢,每秒可能......
  • (转)Delphi编译器版本对照表及工具链
    目录Delphi编译器版本对照表及工具链1、Delphi编译器版本历史对照表2、Delphi工具链(Delphi编译器)3、Delphi条件编译3.1、预定义条件符号:3.2、对编译器版本的条件......
  • delphi 在这之前,有没有人跟里讲过这些知识?
    2023-01-1916:051.在Delphi中,使用access数据库时,如果用户没有安装access,或者安装了一个与程序数据库位数(32/64)不一样的access,都会导致程序无法运行.2.在delphi中......
  • 读编程与类型系统笔记11_高级类型及其他
    1. 范畴论1.1. 范畴论是数学的一个分支,研究的是由对象及这些对象之间的箭头组成的结构1.2. 函子和单子的概念来自范畴论1.3. Haskell是一种编程语言,从范畴论中汲取......
  • 神经网络及其迁移学习
    点头出品,必属精品!!!嘿嘿嘿( ̄y▽, ̄)╭神经网络一、线性模型多元线性模型:$$y=w_1x_1+w_2x_2+...+w_nx_n+b$$其中\(w\)是权重,表示当前权重对应变量\(x\)关于\(y\)的影响......
  • delphi cxgrid记录一些网上都不一定能找到的资料
    主从表的问题.效果图大概如下图所示,它能体现出主表里每一条记录的入仓记录,左边的加减号可以展示与隐藏从表.  结构设计如上图右下角所示,做两个level,和两个DBtab......
  • python基础: 数据类型及其内置方法、类型转换
    目录基本数据类型数据类型的概述1.数据类型之整形--int2.数据类型之浮点型--float3.数据类型之字符型,也称字符串类型--str4.数据类型之列表--list5.数据类型之字典--dict6.......