Fastest way to get text from an RichViewEdit
Posted: Wed Oct 09, 2024 7:36 pm
I am trying to determine which function would be faster.
Any tips?
Any tips?
Code: Select all
function TFmBibleSearch.GetInputText: UnicodeString;
begin
Result := RVGetTextRange(rvInput, 0, RVGetTextLength(rvInput));
//remove new lines
Result :=GlobalUtils.StringReplaceU(Result, #13, '');
Result :=GlobalUtils.StringReplaceU(Result, #10, '');
//remove zero width no-space chars
Result :=GlobalUtils.StringReplaceU(Result, ZWNBSP, '');
end;
Code: Select all
function TFmBibleSearch.GetInputText: UnicodeString;
var
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
rvInput.SaveTextToStreamW('', ms, 0, False, true);
ms.Position := 0;
if ms.Size >0 then begin
SetLength(Result, ms.Size div SizeOf(Char));
ms.ReadBuffer(Result[1], ms.Size);
end
else
Result := '';
ms.Free;
//remove new lines
Result :=GlobalUtils.StringReplaceU(Result, #13, '');
Result :=GlobalUtils.StringReplaceU(Result, #10, '');
//remove zero width no-space chars
Result :=GlobalUtils.StringReplaceU(Result, ZWNBSP, '');
end;