我自己写了两种算法都不理想,请求高人帮帮忙:
下面是我的其中一种算法:function removeBracket(s:ansistring):ansistring;
var
stack1:string;
i,j:integer;
flag:boolean;
begin
flag:=false;
setlength(stack1,length(s));
j:=0;
for i:=0 to length(s)-1 do
begin
if s[i] ='<' then
begin
flag:=true;
Continue;
end;
if s[i]='>' then
begin
flag:=false;
Continue;
end;
if flag then
Continue;
if not flag then
begin
stack1[j]:=s[i];
j:=j+1;
end;end;result:=stack1;
end;
下面是我的其中一种算法:function removeBracket(s:ansistring):ansistring;
var
stack1:string;
i,j:integer;
flag:boolean;
begin
flag:=false;
setlength(stack1,length(s));
j:=0;
for i:=0 to length(s)-1 do
begin
if s[i] ='<' then
begin
flag:=true;
Continue;
end;
if s[i]='>' then
begin
flag:=false;
Continue;
end;
if flag then
Continue;
if not flag then
begin
stack1[j]:=s[i];
j:=j+1;
end;end;result:=stack1;
end;
解决方案 »
- 谁开发过delphi的 DS_8000HC 系列网络硬盘录像机
- 请教:Delphi7的一个BUG
- 关于流操作 分数就100给不了太多 别见怪
- 谁帮忙这段C++Builder代码翻译成DELPHI啊?
- 这么晚了,喝点可乐提提神
- delphi第二张盘上的ABC控件怎么不能用啊?
- 祝大家中秋快乐--送大家超大免费软件包,快来取啦
- 怎样让程序重复运行时自动转到已有的实例中
- *****请问:如果我想在listbox的item.insert时,insert一个Tedit,即制作一个可编辑的listbox.应该如何实现?*****急!急!急!急!***
- 以前学VC的,现在公司要用DELPHI开发,想问问有什么DELPHI书好?
- 给初学者一点建议,答者有分
- 请问:我用了一个Paintbox来画图,我怎么才可以改变他的背景色,就像windows画板那样?
function removeBracket(s:string):string;
var
i,j:integer;
flag:boolean;
begin
flag:=false;
setlength(Result,length(s));
j:=1;
for i:=1 to length(s) do
begin
if s[i] ='<' then flag:=true
else if s[i]='>' then flag:=false
else if not flag then
begin
stack1[j]:=s[i];
Inc(j);
end;
end;
Result[j] := #0;
Result := PChar(Result);
end;
function removeBracket(s:string):string;
var
i,left,right : integer;
begin
while ((pos('<',s)<>0) or (pos('>',s)<>0)) do
begin
left := pos('<',s);
right := pos('>',s);
delete(s,left,right-left+1);
end;
result := s;
end;
var
i,j:integer;
flag:boolean;
begin
flag:=false;
setlength(Result,length(s));
j:=1;
for i:=1 to length(s) do
begin
if s[i] ='<' then flag:=true
else if s[i]='>' then flag:=false
else if not flag then
begin
Result[j]:=s[i]; // !!!
Inc(j);
end;
end;
Result[j] := #0;
Result := PChar(Result);
end
如果还要去其他东西,建议作个词法分析程序,delphi vcl中有个TParse可以参考