问字符串问题(比较菜的问题,请别笑我)(10分)

  • 主题发起人 主题发起人 apacheii
  • 开始时间 开始时间
A

apacheii

Unregistered / Unconfirmed
GUEST, unregistred user!
请问怎样实现“Edit1.Text”的内容是“Edit2.Text”滤除“Edit3.Text”的结果?<br>就是说字符串1的内容是字符串2去掉字符串3,当然字符串3的长度小于字符串2!
 
用pos再用Delete。
 
http://www.skin-studio.com
 
谢谢,有没有具体一点的代码?
 
试试数据结构中很基本,很重要的模式匹配算法!
 
var <br>&nbsp; &nbsp;NewStr, Str, SubStr: String;<br>&nbsp; &nbsp;I, Len: Integet;<br>begin<br>&nbsp; I := Pos(SubStr, Str);<br>&nbsp; if I &gt;= 0 then<br>&nbsp; &nbsp; NewStr := Delete(Str, I, Length(SubStr);
 
Edit1.Text := StringReplace(Edit2.Text,Edit3.Text,'',[rfReplaceAll, rfIgnoreCase]);<br>
 
To:NATASHA:请详细解释一下好吗?<br>var <br>&nbsp; &nbsp;NewStr, Str, SubStr: String;<br>&nbsp; &nbsp;I, Len: Integet;<br>begin<br>&nbsp; I := Pos(SubStr, Str);<br>&nbsp; if I &gt;= 0 then<br>&nbsp; &nbsp; NewStr := Delete(Str, I, Length(SubStr);<br><br>NewStr := Delete(Str, I, Length(SubStr);//这句有错误!<br>Pos(SubStr, Str)起什么作用?<br>Delete(.......)的用法?<br>Length(String)是求String的长度吧?<br><br>To realLearning:<br>Edit1.Text := StringReplace(Edit2.Text,Edit3.Text,'',[rfReplaceAll, rfIgnoreCase]);<br>这句好象不对呀?<br><br>
 
NewStr := Delete(Str, I, Length(SubStr);//这句有错误!<br>改为NewStr := Delete(Str, I, Length(SubStr));<br><br>Pos(SubStr, Str)起什么作用?<br>&nbsp; 例如:<br>&nbsp; &nbsp;SubStr:='gh';<br>&nbsp; &nbsp;Str:='bcdefghi';<br>&nbsp; &nbsp;Pos(SubStr, Str); &nbsp;//结果为6<br><br>&nbsp; &nbsp;SubStr:='gh9';<br>&nbsp; &nbsp;Str:='bcdefghi';<br>&nbsp; &nbsp;Pos(SubStr, Str); &nbsp;//结果为0<br><br><br>&nbsp; <br>Delete(.......)的用法?<br>&nbsp; &nbsp;<br>&nbsp; 例如:<br>&nbsp; &nbsp;Str:='bcdefghi';<br>&nbsp; &nbsp;Delete(Str,5,1); &nbsp;//结果为'bcdeghi'<br>&nbsp; &nbsp;Delete(Str,5,2); &nbsp;//结果为'bcdehi'<br>&nbsp; &nbsp;Delete(Str,5,3); &nbsp;//结果为'bcdei'<br><br><br>Length(String)是求String的长度吧? &nbsp;是的<br><br>
 
To:yhh<br>&nbsp; &nbsp;谢谢,你的解释很详细,不过我还是不太明白Pos是什么意思?<br>是不是求'SubStr'在'Str'的第几位?<br><br>To:NATASHA<br>&nbsp; &nbsp;谢谢你的热心帮助:)
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
922
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部