delphi截取字符串的方法


本文整理自网络,侵删。

 function GetStr(StrSource,StrBegin,StrEnd:string):string;   //(源字符串,开始字符串,结束字符串)
var   
in_star,in_end:integer;   
strtmp:string;   
begin   
in_star:=AnsiPos(strbegin,strsource)+length(strbegin);   
strtmp:=copy(strsource,in_star,length(strsource));   
in_end:=AnsiPos(strend,strtmp);   
result:=copy(strsource,in_star,in_star + in_end-in_star -1);   
end;  

Delphi代码2、

 

function GetStr_n(StrSource,StrBegin:string;ACount:Integer):string;   //(源字符串,开始字符串,开始字符串后面几个字符)
var   
in_star:integer;   
begin   
in_star:=AnsiPos(strbegin,strsource)+length(strbegin);   
result:=copy(strsource,in_star,ACount);   
end;  

 

//方法2

uses StrUtils;

      首部 function MidStr(const AText: string; const AStart, ACount: Integer): 
      string; $[StrUtils.pas
      功能 返回字符串AText从AStart开始的ACount个字符
      说明 其实就是Copy
      参考 function System.Copy
      例子 Edit3.Text := MidStr(Edit1.Text, SpinEdit1.Value, SpinEdit2.Value);

//去掉字符串中空格
  Trim()去掉字符串左右两边的空格和控制符,它的使用语法如下:

   function Trim(const S: string): string;

  TrimLeft()用于去除字符串左边的空格,它的使用方法如下:

   function TrimLeft(const S: string): string;

  TrimRight()用于去除字符串右边的空格,它的使用方法如下:

   function TrimRight(const S: string): string;

 

UpperCase():将字符串小写转为大写   
LowerCase()将大写转为小写

相关阅读 >>

Delphi xe7检查android蓝牙权限

Delphi检测程序内存泄漏

Delphi x 的 y 次方

Delphi 把窗体客户区图像保存到文件或剪切板

Delphi 如何判断一个exe文件是否运行

Delphi安全结束线程

Delphi获取系统电源状态的信息

Delphi tnethttpclient的用法

Delphi的tfilestream

Delphi获取千千静听歌词下载地址源码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...