请问delphi中是否有类似replace这样的替换字符串中指定字符的函数?(20分)

  • 主题发起人 主题发起人 灰云1
  • 开始时间 开始时间

灰云1

Unregistered / Unconfirmed
GUEST, unregistred user!
请问是否有类似replace这样的替换字符串中指定字符的函数?
 
给你写了一个 :<br><br>&gt;替换字符串中指定字符,以ch2替换ch1:<br>function ReplaceCharFast (const s: string; <br>&nbsp; ch1: char; ch2: char): string; <br>var i: integer; <br>begin <br>&nbsp; Result := s; <br>&nbsp; for i := 1 to length (Result) do <br>&nbsp; &nbsp; if Result = ch1 then <br>&nbsp; &nbsp; &nbsp; Result := ch2; <br>end;
 
StringReplace function<br>------------------------------------------<br>Returns a string with occurrences of one substring replaced by another <br>substring.<br><br>Unit<br>Sysutils<br><br>Category<br><br>string handling routines<br><br>type<br>&nbsp; TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);<br>function StringReplace(const S, OldPattern, NewPattern: string<br>; Flags: TReplaceFlags): string;<br><br>Description<br><br>StringReplace replaces occurrences of the substring specified by OldPattern <br>with the substring specified by NewPattern. StringReplace assumes that the <br>source string, specified by S, may contain Multibyte characters.<br><br>If the Flags parameter does not include rfReplaceAll, StringReplace only <br>replaces the first occurrence of OldPattern in S. Otherwise, all instances <br>of OldPattern are replaced by NewPattern.<br><br>If the Flags parameter includes rfIgnoreCase, The comparison operation is <br>case insensitive.<br><br>
 
请用我给你提供的DELPHI 函数StringReplace吧,又快又方便:-)<br>
 
function Replace(const szSrc:string; szSubStr:string; szReplace:string) : string;<br>var<br>&nbsp; idx : integer;<br>begin<br>&nbsp; result := szSrc;<br>&nbsp; idx := Pos(szSubStr, szSrc);<br>&nbsp; if idx &gt; 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; Delete(result, idx, Length(szSubStr));<br>&nbsp; &nbsp; Insert(szSubStr, result, idx);<br>&nbsp; &nbsp; end;<br>end;<br>
 
多谢各位啦
 
后退
顶部