找回密码
 立即注册
查看: 539|回复: 0

DELPHI 将字符串中某个字符串替换成其他字符串

[复制链接]

194

主题

0

回帖

986

积分

管理员

积分
986
发表于 2024-6-15 17:27:49 | 显示全部楼层 |阅读模式
function StringReplace (const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;

rfReplaceAll:全部替换
rfIgnoreCase:忽略大小写
For Example:

var
aStr: String;
begin
aStr := 'This is a book, not a pen!';
ShowMessage(StringReplace (aStr, 'a', 'two', []));//This is two book, not a pen!只替换了第一个符合的字
ShowMessage(StringReplace (aStr, 'a', 'two', [rfReplaceAll]));//This is two book, not two pen!替换了所有符合的字
aStr := 'This is a book, not A pen!';
ShowMessage(StringReplace (aStr, 'a', 'two', [rfReplaceAll]));//This is two book, not A pen!只替换了符合的字(小写a)
ShowMessage(StringReplace (aStr, 'a', 'two', [rfReplaceAll, rfIgnoreCase]));//This is two book, not two pen!不管大小写替换了所有符合的字
end;
商务合作
业务洽谈
Wechat:S3-SH-CN  
QQ群:128669090
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|S3软件

GMT+8, 2026-6-6 08:06 , Processed in 0.037457 second(s), 19 queries .

Powered by S3

©2001-2025 S3 Team.

快速回复 返回顶部 返回列表