Solved

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

Posted on 2004-09-08
5
291 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
ID: 12007093
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
ID: 12007155
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
ID: 12007164
leength=length. Sorry, typo...
0
 
LVL 14

Assisted Solution

by:Pierre Cornelius
Pierre Cornelius earned 25 total points
ID: 12008109
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
ID: 12008391
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
automatically logging in via bde delphi 3 69
Working this component WebCopy with proxy, help 3 76
how to center only a line in richedit? 4 52
Delphi XE10 Round Image 2 77
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

21 Experts available now in Live!

Get 1:1 Help Now