?
Solved

If first line of memo starts with either http:// or www. do something?

Posted on 2009-05-04
4
Medium Priority
?
277 Views
Last Modified: 2012-05-06
Hi folks,

The title is quite selfexplanatory but nonetheless, I have this application which extracts certain portions of text between certain tags I fill memo1 with sourcode after which a button press filles memo2 with all the text portions that occur between two defined tags.

Now after this is done I want the app to count the number of links. This is only useful when it contains the links.

I\m planning on using the onChange event but dont know how to code this yet.

Thanks in advance,

Dweeep
0
Comment
Question by:PeterdeB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Assisted Solution

by:Johnjces
Johnjces earned 400 total points
ID: 24295713
Can you use Pos such as:

of (pos('http://', memo1.lines[0] > 0) or (pos('www', memo1.lines[0] > 0)  then
 ...// do something

This checks just your first line only.


Do a for loop to check other lines.

Hope this helped.

John
0
 
LVL 18

Assisted Solution

by:Johnjces
Johnjces earned 400 total points
ID: 24295732
Again, my keyboard cannot type!

the 'of' is supposed t o be IF.

if (pos.....

John
0
 
LVL 12

Accepted Solution

by:
Hypo earned 1600 total points
ID: 24302716
Hi,
Some things you should be aware of is that the Pos function is case sensetive, so while it would detect 'http://' or 'www' in the example above, it would not detect 'HTTP://' or 'WWW'. If you don't want the Pos to be case sensetive, then you would have to convert both strings to capitals using the function UpperCase (one way to do it), e.g. Pos('HTTP://', UpperCase(Memo1.Lines[i]));

Another thing is that the Pos function returns the position of a substring in a string, which means that in the example above, it will detect 'http://' or 'www' in any locations of the strings, so the string ' abc 123 www ' would result in a match as well. If you only want to detect if the string starts with 'http://' or 'www', then you should test that it returns the first position, as in this line "Pos('http://', memo1.lines[i]) = 1". However there are easier ways to do this test.

If you want to test if the string only starts with a text, then you could use AnsiStartsText which exists in the StrUtils unit (in later versions of delphi the function StartsText also exist). The function AnsiStartsText is case insensetive, which means that it would detect 'www' as well as 'WWW'. Also if you want to ignore any white spaces in the start of the text, before you do your string match, then you could use the TrimLeft function on all the lines you test (TrimLeft removes all the whitespace characters in the start of the string), e.g. the reason to use TrimLeft is to detect 'www' as well as '   www' but not 'abc www'.

The example below uses a Memo and a Label on a Form. connect the Memo1Change event to run.

regards
Hypo
procedure TForm1.Memo1Change(Sender: TObject);
var i, j : Integer;
begin
  j := 0;
  for i := 0 to memo1.Lines.Count-1 do
    if (AnsiStartsText('http://', TrimLeft(memo1.lines[i])) or AnsiStartsText('www', TrimLeft(memo1.lines[i])))
      then inc(j); // Do your stuff...
  label1.Caption := IntToStr(j);
end;

Open in new window

0
 

Author Closing Comment

by:PeterdeB
ID: 31577508
Many thanks!

@ Johnjces > your comment would do
@ Hypo > yours is more accurate and complete

That's why I split the points :)

Dweep
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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