用循环做就可以了:
tmpstr := 'a*1c问题d*2e急g*3h';
for I := 1 to 3 do
begin
repstr := '*' + inttostr(I);
J := pos(repstr,tmpstr);
if J <> 0 then
begin
tmpstr := copy(1,J,tmpstr) + 'M' + copy(J + 2,length(tmpstr) -J -1,tmpstr);
end;
end;暂时没有测试,不过应该没有问题
tmpstr := 'a*1c问题d*2e急g*3h';
for I := 1 to 3 do
begin
repstr := '*' + inttostr(I);
J := pos(repstr,tmpstr);
if J <> 0 then
begin
tmpstr := copy(1,J,tmpstr) + 'M' + copy(J + 2,length(tmpstr) -J -1,tmpstr);
end;
end;暂时没有测试,不过应该没有问题
解决方案 »
- listview中间的线,怎么设置???
- COM+组件注册问题。
- 问一个LISTVIEW属性的问题?
- 欢迎加入DELPHI_FANS群:5985639,在线交流一下,源码共享
- 谁有关于websnap登陆的完整例子啊?
- sql语句错误!
- 动态创建按钮和text框,可动态设置这些控件的caption或text属性。
- 一个简单问题?
- 请问socket5代理和用socket做代理有什么联系,我做了一个代理服务器软件,但是不能代理oicq!为什么?
- 求助:各位大哥请帮我看看这个字符串问题,谢谢!
- 有没有比较直接的字符串替换函数?例如:replace(子串,替换串,母串)
- 已经有很多人问过了,但答案都不满意,高分求解关于IE的保存问题。
a:=stringReplace(a,'*1','M',[rfReplaceAll]);
a:=stringReplace(a,'*2','M',[rfReplaceAll]);
a:=stringReplace(a,'*3','M',[rfReplaceAll]);
如果你的*1,*2,*3是变的,那你写个循环从1到9就行了。
tmpstr := copy(tmpstr,1,J-1) + 'M' + copy(tmpstr,J + 2,length(tmpstr) -J -1);
StringReplace(sToHandle, '*', 'M', [rfReplaceAll])
StringReplace(sToHandle, '1', '', [rfReplaceAll])去掉所有数字1。
最终写成"a*M*c问题d*M*e急g*M*h"
var
I: Integer;
B: Boolean;
begin
Result := '';
B := True;
for I := 1 to Length(mStr) do
if B then
if mStr[I] = '*' then
B := False
else Result := Result + mStr[I]
else if mStr[I] = '*' then begin
Result := Result + '*M*';
B := True;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := f('a*12一*c问题d*24二567*e急g*3k三d98*h');
end;
var
I: Integer;
B: Boolean;
begin
Result := '';
B := True;
for I := 1 to Length(mStr) do
if B then
if mStr[I] = '*' then
B := False
else Result := Result + mStr[I]
else if mStr[I] = '*' then begin
Result := Result + 'M'; //修改
B := True;
end;
end;
var
i :integer;
sStr,sResult,sTmpStr :string;
bIsFirst :boolean;
begin
bIsFirst := false;
sResult := '';
sStr := trim(sTmp);
for i:= 1 to Length(sStr) do
begin
sTmpStr := copy(sStr,i,1);
if bIsFirst then
begin
if sTmpStr = '*' then
begin
bIsFirst := false;
sResult := sResult + 'M' +sTmpStr;
end;
end
else
begin
if sTmpStr = '*' then
begin
bIsFirst := true;
end;
sResult := sResult + sTmpStr;
end;
end;
Result := sResult ;
end;procedure TForm1.Button1Click(Sender: TObject);
var
sTmp :string;
begin
sTmp := 'a*12一*c问题d*24二567*e急g*3k三d98*h';
sTmp := getTheSubStr(sTmp);
Application.MessageBox(pchar(sTmp),'答案',MB_OK+MB_ICONINFORMATION);
end;