Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 853553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:46:40+00:00 2026-05-15T07:46:40+00:00

I’ve got a report that’s supposed to take a grid control and produce HTML

  • 0

I’ve got a report that’s supposed to take a grid control and produce HTML output. One of the columns in the grid can display any of a number of values, or <Any>. When this gets output to HTML, of course, it ends up blank.

I could probably write up some routine to use StringReplace to turn that into &lt;Any&gt; so it would display this particular case correctly, but I figure there’s probably one in the RTL somewhere that’s already been tested and does it right. Anyone know where I could find it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:46:41+00:00Added an answer on May 15, 2026 at 7:46 am

    I am 99 % sure that such a function does not exist in the RTL (as of Delphi 2009). Of course – however – it is trivial to write such a function.

    Update

    HTTPUtil.HTMLEscape is what you are looking for:

    function HTMLEscape(const Str: string): string;
    

    I don’t dare to publish the code here (copyright violation, probably), but the routine is very simple. It encodes “<“, “>”, “&”, and “”” to &lt;, &gt;, &amp;, and &quot;. It also replaces characters #92, #160..#255 to decimal codes, e.g. &#92;.

    This latter step is unnecessary if the file is UTF-8, and also illogical, because higher special characters, such as ∮ are left as they are, while lower special characters, such as ×, are encoded.

    Update 2

    In response to the answer by Stijn Sanders, I made a simple performance test.

    program Project1;
    
    {$APPTYPE CONSOLE}
    
    uses
      Windows, SysUtils;
    
    var
      t1, t2, t3, t4: Int64;
      i: Integer;
      str: string;
    const
      N = 100000;
    
    
    function HTMLEncode(const Data: string): string;
    var
      i: Integer;
    begin
    
      result := '';
      for i := 1 to length(Data) do
        case Data[i] of
          '<': result := result + '&lt;';
          '>': result := result + '&gt;';
          '&': result := result + '&amp;';
          '"': result := result + '&quot;';
        else
          result := result + Data[i];
        end;
    
    end;
    
    function HTMLEncode2(Data: string):string;
    begin
      Result:=
        StringReplace(
        StringReplace(
        StringReplace(
        StringReplace(
          Data,
          '&','&amp;',[rfReplaceAll]),
          '<','&lt;',[rfReplaceAll]),
          '>','&gt;',[rfReplaceAll]),
          '"','&quot;',[rfReplaceAll]);
    end;
    
    begin
    
      QueryPerformanceCounter(t1);
      for i := 0 to N - 1 do
        str := HTMLEncode('Testing. Is 3*4<3+4? Do you like "A & B"');
      QueryPerformanceCounter(t2);
    
      QueryPerformanceCounter(t3);
      for i := 0 to N - 1 do
        str := HTMLEncode2('Testing. Is 3*4<3+4? Do you like "A & B"');
      QueryPerformanceCounter(t4);
    
      Writeln(IntToStr(t2-t1));
      Writeln(IntToStr(t4-t3));
    
      Readln;
    
    
    end.
    

    The output is

    532031
    801969
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.