Solved

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

Posted on 2004-09-08
5
292 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Check Delphi Seattle IOS app without MAC ? 1 97
add combobox item based on numbers 9 141
SUM 2 INTEGER ARRAYS INTO 1 10 100
Twebbrowser add css to the header 3 24
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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