在Delphi中用什么函数能直接实现‘AB:CD:EF’为‘AB-CD-EF’,即将:用-换掉。(10分)

  • 主题发起人 xuekunli
  • 开始时间
X

xuekunli

Unregistered / Unconfirmed
GUEST, unregistred user!
在Delphi中用什么函数能直接实现‘AB:CD:EF’为‘AB-CD-EF’,即将:用-换掉。
 
自已写个函数就不行吗???<br>&nbsp; &nbsp; procedure ReplaceChar(OldChar,NewChar: Char;var AStr: string);<br>&nbsp; &nbsp; var iPos: integer;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; iPos := Pos(OldChar,AStr);<br>&nbsp; &nbsp; &nbsp; &nbsp; while iPos&gt;0 do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AStr[iPos] := NewChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iPos := Pos(OldChar,AStr);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;
 
用StringReplace函数
 
使用函数StringReplace<br>如:<br>L1:=StringReplace('AA:CD:EF,':','-',[rfReplaceAll]);<br>运算后L1就是'AB-CD-EF'了。<br><br>
 
Block_K_E 的方法
 
StringReplace真是有用。<br>
 
str:=StringReplace('AA:CD:EF,':','-',[rfReplaceAll]);<br>
 
顶部