[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Text2HTML function

Posted on 1999-11-02
10
Medium Priority
?
373 Views
Last Modified: 2010-04-04
Does anyone know of a 'Text2HTML function', i.e. a function that will take a string as input and as result return the same string, but now with all HTML-significant characters replaced by their HTML-safe equivalents, e.g. '<' -> '&lt', '&' -> '&amp' etc.

The function / procedure must be usable from a Delphi program. Though the function is not too complicated, I would rather not invent this deep plate again, since I am sure someone has already done it.

Regards,
AndersWP
0
Comment
Question by:AndersWP
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2178350
listening
0
 
LVL 4

Expert Comment

by:mhervais
ID: 2178374
On the contrary, this function is not so easy to write because you must make the distinction between html significant characters, and html alike characters embbedded in text.

I did the reverse functionnality you speak about, htlm to text in order to analyze pages, and I had to write a parser.

and Even like that, I don't get 100% of success because the browsers allow syntax that does not exactly fulfil the html specifications

regards, Marc
0
 
LVL 1

Author Comment

by:AndersWP
ID: 2179263
My needs are a bit simpler, since I can assume that my text does not contain any HTML tags. So I would think that a relatively simple substitution would do the trick.

Regards,
AndersWP
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 1

Expert Comment

by:JoeBooth
ID: 2179927
Although I don't have all of the tags in front of me, here is a start for you.

function Text2HTML(cIn:string):string;
const
   aIn  : array[0..2] of string =  
            ( '>','<','&');
   aOut : array[0..2] of string =
            ( '&gt','&lt','&amp');
var
   y,j,nSize : integer;
   cChar     : string;
begin
   result := '';
   nSize  := length(cIn);

   for j := 1 to nSize do
   begin
      cChar := copy(cIn,j,1);
      for y := 0 to 2 do
      begin
         if cChar=aIn[y] then
         begin
            cChar := aOut[y];
            break;
         end;
      end;
      result := result+cChar;
   end;
end;
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2180828
If its just big blocks of text you could use the PRE tag (still need to vonvert '<' though).

Cheers,
Raymond.
0
 
LVL 1

Expert Comment

by:fulg0re
ID: 2182385
well, use this code... enjoy.
brr.... browser can't insert it correctly... will send by email...
hmm... tell me your email and i'll send you...
0
 
LVL 1

Author Comment

by:AndersWP
ID: 2182672
JoeBooth, thanks for the code sample. As you demonstrate, the mechanics of the function is not complex. I merely wondered if someone has already done it, so I won't have to do it again.

rwilson, I would rather not use the PRE tag, since this means that my text will be formatted exactly as entered, and that is not acceptable.

fulGore, I would very much like to see the code you mention. My email is AndersWP@ELK.dk. I had to reject your answer in order to be able to make this comment. If your code looks good, you can just repost a dummy answer and get the points.

Regards,
AndersWP
0
 
LVL 1

Author Comment

by:AndersWP
ID: 2258913
fulgOre, you have some points coming to you if you post your answer.

AndersWP
0
 
LVL 1

Accepted Solution

by:
fulg0re earned 300 total points
ID: 2261067
hi there anders!
i've been away for a while...
10x for the points (seems like u cared buot them more than i did :)

btw. what's up with your developement?
0
 
LVL 1

Author Comment

by:AndersWP
ID: 2261391
Thanks for the help.

Regards,
AndersWP
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question