delphi 根据特殊符号字符获取字符串前或后的字符


本文整理自网络,侵删。

 
function GetBefore(substr, str:string):string;
{?Drkb v.3(2007): www.drkb.ru, 
?Vit (Vitaly Nevzorov) - nevzorov@yahoo.com}
begin
if pos(substr,str)>0 then
  result:=copy(str,1,pos(substr,str)-1)
else
  result:='';
end;


function GetAfter(substr, str:string):string;
{?Drkb v.3(2007): www.drkb.ru, 
?Vit (Vitaly Nevzorov) - nevzorov@yahoo.com}
begin
if pos(substr,str)>0 then
  result:=copy(str,pos(substr,str)+length(substr),length(str))
else
  result:='';
end;
 

演示:

1) 
GetBefore('-', 'Total-2.00$') // 结果 "Total"

2) 
GetAfter('-', 'Total-2.00$') // 结果 "2.00$"

3) 
GetBefore('$',GetAfter('-', 'Total-2.00$ (общая сумма)')  // 结果 "2.00"

相关阅读 >>

Delphi 使用google translate实现tts

Delphi 在运行时改变控件的大小

Delphi tform类有关属性简介

Delphi idhttp1下载文件防止假死

Delphi [android]获取屏幕的物理分辨率

Delphi 制作一个内网传播的程序

Delphi http post json示例

Delphi xe7开发的获取网页中字符串的编码是否是utf8

Delphi 时钟

Delphi应用程序 paramstr()带有参数

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



打赏

取消

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

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

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

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

评论

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