This is a list of functions to handle strings in Delphi. It will be update periodically.
Function Stream to String.
If you wanna convert a stream to a string you need to create a TMemoryStream variable and use the function SetString to put the result string
function StreamToString(Stream : TStream) : String; var ms : TMemoryStream; begin Result := ''; ms := TMemoryStream.Create; try ms.LoadFromStream(Stream); SetString(Result,PChar(ms.memory),ms.Size); finally ms.free; end; end;
Function Replace Char
To replace a char with other character you should make a loop until that char is not find in the string. If it is found in the string then replace with the new character. To find position of a character in a string you should use the function pos and return the position in the string where it was found. If it was not found pos returns -1
function ReplaceChar(s:string;c:char;charrep:char):string; begin while pos(c,s)>0 do s[pos(c,s)]:=charrep; ReplaceChar:=s; end;
Function Remove Tags
Function RemoveTags(s:string):string; var k1:integer; s1:string; canwrite:boolean; begin s1:=''; canwrite:=true; for k1:=1 to length(s) do begin if s[k1]='<' then canwrite:=false else if s[k1]='>' then canwrite:=true else begin if canwrite then s1:=s1+s[k1]; end; end; RemoveTags:=s1; end;