[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2009-05-04
4
Medium Priority
?
285 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

656 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