Solved

Delete Characters that do not begin with "http" in TMemo

Posted on 2004-09-08
5
290 Views
Last Modified: 2010-04-05
Hello All;

  I need to Delete all Characters in a TMemo that do not begin
With the               http://

Lets say that you have these sets:


http://somedomain.com
http://www.somedomain.com
some/thing/like/this.html
some/other/thing/


2nd:
I need to get rid of any link that begins with

http://wrongdomain.com/
http://www.wrongdomain.com/

At the end of the above URL's is added text links
To sub-categories. I need to have ANYTHING that begins
With the beginning Main-URL to be removed from the TMemo.
( They all very, and are never the same )

Thank You
carrzkiss
0
Comment
Question by:Wayne Barron
5 Comments
 
LVL 4

Accepted Solution

by:
Evarest earned 75 total points
Comment Utility
If you have on each line either text or a hyperlink, you can use the following:

for Q :=Memo1.Lines.Count -1 downto 0 do
 begin
  if pos( 'http://', lowercase(Memo1.Lines[Q]) ) = 0
   then Memo1.Lines.Delete(Q);
 end;

Kind regards,
Evarest
0
 
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 25 total points
Comment Utility
What's so difficult about that? Dump it in a stringlist, start removing lines from the last line upwards to 0 where the position of 'http://' cannot be found at position 1 of the line... Since you already have everything in a TMemo, use the TMemo.Lines property.

const http = 'HTTP://';
var I:Integer;
begin
  for I := Pred(YourMemo.Lines.Count) downto 0 do
    if not AnsiSameText(copy(YourMemo.Lines[I], 1, leength(http), http) then
      YourMemo.Lines.Delete(I);
end;

Something like that?
Just use the Delphi string functions on the Memo.Lines[Index] strings. And remember, if you're going to remove lines, start looping through the list from the last line down to 0.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
Comment Utility
leength=length. Sorry, typo...
0
 
LVL 14

Assisted Solution

by:Pierre Cornelius
Pierre Cornelius earned 25 total points
Comment Utility
Here's a easy all in one solution:

procedure CleanList(var m: TMemo; Exclusions: TStrings);
  function DeleteLine(s: string):boolean;
  var i: integer;
  begin
    result:= Uppercase(copy(m.Lines[i],1, 7)) <> 'HTTP://';
    if not result then
    for i:= 0 to Exclusions.Count-1 do
      if (copy(s,1, Length(Exclusions[i])) = Exclusions[i]) then
        begin
          result:= true;
          break;
        end;
  end;
var i,j: integer;
begin
  i:= 0;
  while i < m.Lines.Count do
  begin
    if DeleteLine(m.Lines[i])
      then m.Lines.Delete(i)
      else i:= i+1;
  end;
end;

USAGE: I had 2 memo's on the form
=====

procedure TForm1.Button1Click(Sender: TObject);
begin
  CleanList(memo1, memo2.Lines);
end;

Regards
Pierre
0
 
LVL 30

Author Comment

by:Wayne Barron
Comment Utility
Thank you everyone;

  I split the points to everyone. But for the easiest and quickiest
Solution I gave [Evarest] 75 Points for his solution.

The other codes may come in handy for "Learning Purposes"
For me and others with the same issue's.

Thank you all once again.
very fast answers.

carrzkiss
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now