请问怎样删除字符串中的指定的子串?

ATCG 2003-08-05 04:30:56
请问怎样删除字符串中的指定的子串?
...全文
182 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ATCG 2003-08-05
  • 打赏
  • 举报
回复
我这样写为什么报错啊
edit2.text:=stringreplace(edit1.text,'"','',rfReplaceAll);

[Error] Unit1.pas(30): Incompatible types: 'TReplaceFlags' and 'Enumeration'
李_军 2003-08-05
  • 打赏
  • 举报
回复
用StringReplace好了
楚人无衣 2003-08-05
  • 打赏
  • 举报
回复
StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;

用''代替你要删除的就OK了,试一试!
wdsimon 2003-08-05
  • 打赏
  • 举报
回复
呵呵,来晚了
gangnet 2003-08-05
  • 打赏
  • 举报
回复
自己写一个函数:
function deletestr(str1:string;str2:string):string;
var
p,l1,l2:integer;
str:string;
begin
result:=str1;
l1:=length(str1);
l2:=length(str2);
p:=pos(str2,str1);
if p>0 then
result:=copy(str1,1,p-1)+copy(str1,p+l2,l1-p-l2+1);
end;
江山易改 2003-08-05
  • 打赏
  • 举报
回复
上面的函数将所有包括Substr的字符都删除
江山易改 2003-08-05
  • 打赏
  • 举报
回复
function dele_Str(substr, Str :string) :string ;
begin
if Pos(substr,Str) < 1 then
begin
Result := Str ;
end
else
begin
Result :=Result + dele_Str(substr, Copy(Str,1,Pos(substr,Str)-1)
+Copy(Str,Pos(substr,Str)+length(substr),Length(Str)-(Pos(substr,Str)+length(substr))) );
end ;
end ;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption :=dele_Str('123','1235888558123');
end;

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧