Results 1 to 3 of 3

Thread: Replace() Function

  1. #1

    Replace() Function

    I made this function tonight and thought it'd be usefull to share. Not that it's hard to code, but just something to share (and get feedback on how to make faster )

    This function is to find and replace all instances of a substring in a string.

    [pascal]function Replace(FindStr, ReplaceWith, Source : String) : String;
    var i,c : integer;
    begin
    c := Length(FindStr);
    i := Pos(FindStr, Source);
    while i <> 0 do
    begin
    Source := Copy(Source, 1, i - 1) + ReplaceWith + Copy(Source, i + c, Length(Source));
    i := Pos(FindStr, Source);
    end;
    Result := Source;
    end;[/pascal]
    I have a 2005 CRF 250 so &lt;^&gt;(&gt;&lt&lt;^&gt;
    <br />http://www.gtrpg.com/

  2. #2

    Replace() Function

    It seems kind of odd to rewrite a function that is already in the RTL, unless it is specifically being written to be faster than the RTL version. StringReplace has already been rewritten to be a lot faster as part of the FastCode project.
    http://dennishomepage.gugs-cats.dk/A...eChallenge.htm

  3. #3

    Replace() Function

    ... I had no idea there was a function already... OH:
    I have a 2005 CRF 250 so &lt;^&gt;(&gt;&lt&lt;^&gt;
    <br />http://www.gtrpg.com/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •