andyhill Posted June 19, 2020 Share Posted June 19, 2020 How can I get the Plain Text from the HtmlMemo ? MyLines(TStringList) in code at runtime. MyLines.SetStrings(HtmlMemo.Lines); // I want plain text CRLF for each line Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 19, 2020 Share Posted June 19, 2020 20 minutes ago, andyhill said: How can I get the Plain Text from the HtmlMemo ? What is your HTML string for example? Quote Link to comment Share on other sites More sharing options...
andyhill Posted June 19, 2020 Author Share Posted June 19, 2020 Hello <b style=""><font color="#ff0000">Hello</font></b> I need text "Hello" only (no markup) Quote Link to comment Share on other sites More sharing options...
Ronbral Posted June 20, 2020 Share Posted June 20, 2020 You must use an HTML Parse to extract any content from the HTML document. I use CleverSuite, which has this functionality. But there are many libraries on the market for this purpose. Quote Link to comment Share on other sites More sharing options...
andyhill Posted June 20, 2020 Author Share Posted June 20, 2020 Yes, I was hoping for UniGUI to provide this capability - Thanks Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 20, 2020 Share Posted June 20, 2020 3 hours ago, andyhill said: <b style=""><font color="#ff0000">Hello</font></b> I need text "Hello" only (no markup) 27 minutes ago, andyhill said: Yes, I was hoping for UniGUI to provide this capability - Thanks For start, you can try to use this approach: procedure TMainForm.UniButton1Click(Sender: TObject); function StripHTML(S: string): string; var TagBegin, TagEnd, TagLength: integer; begin TagBegin := Pos( '<', S); while (TagBegin > 0) do begin TagEnd := Pos('>', S); TagLength := TagEnd - TagBegin + 1; Delete(S, TagBegin, TagLength); TagBegin:= Pos( '<', S); end; S := StringReplace(S, ' ', ' ', [rfReplaceAll]); Result := S; end; begin UniMemo1.Lines.Text := StripHTML(UniHTMLMemo1.Lines.Text) end; Quote Link to comment Share on other sites More sharing options...
andyhill Posted June 20, 2020 Author Share Posted June 20, 2020 Thank you Sherzod, I used the very same code however I could not remove the - do you have an answer for that ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 20, 2020 Share Posted June 20, 2020 2 minutes ago, andyhill said: I could not remove the - do you have an answer for that ? S := StringReplace(S, ' ', ' ', [rfReplaceAll]); //<----- Result := S; Quote Link to comment Share on other sites More sharing options...
andyhill Posted June 20, 2020 Author Share Posted June 20, 2020 No, it fails to remove, try it (Delphi 10.3) Quote Link to comment Share on other sites More sharing options...
Mehmet Emin Posted June 20, 2020 Share Posted June 20, 2020 Do you have the option to process this in browser ? HTMLElement.innerText would do it. Then you can send it to server. Quote Link to comment Share on other sites More sharing options...
andyhill Posted June 23, 2020 Author Share Posted June 23, 2020 I can remove NBSP if I refer to it as #$A0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.