Almost every text editor / word processor has the ability to search for a given string and replace it with another. If you're planning on adding similar functionality to your application, here's an example of where all of it can start:
function SearchAndReplace( sSrc, sLookFor, sReplaceWith : string ) : string; var nPos, nLenLookFor : integer; begin nPos := Pos( sLookFor, sSrc ); nLenLookFor := Length( sLookFor ); while(nPos > 0)do begin Delete( sSrc, nPos, nLenLookFor ); Insert( sReplaceWith, sSrc, nPos ); nPos := Pos( sLookFor, sSrc ); end; Result := sSrc; end; |
SearchAndReplace( 'this,is,a,test', ',', ' ' ) |
Source : http://www.chami.com/tips/delphi/010197D.html