Solved

String function in delphi

Posted on 2011-03-06
5
426 Views
Last Modified: 2012-08-13
Hello experts!
Please help me.

I have a list of websites.
I need to create a function that determinates what is the site extension (.ru or .com)

Plese help me.
Thanks
0
Comment
Question by:helyonprime96
  • 2
  • 2
5 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 35046418
Sure here you are:
function Exturl(url: string): string;
begin
  url := StringReplace(url,'http://','',[rfIgnoreCase]);
  url := StringReplace(url,'www.','',[rfIgnoreCase]);
  if pos('/',url) > 0 then
    result := copy(url,pos('.',url),pos('/',url)-pos('.',url))
  else
    result := copy(url,pos('.',url),length(url));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage(Exturl('test.com'));
end;

Open in new window

0
 

Author Closing Comment

by:helyonprime96
ID: 35046456
thanks, it works
0
 

Author Comment

by:helyonprime96
ID: 35046485
please help me, how i can see this text between
<td valign="top">
and </td>

thanks
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35046486

try



procedure TForm3.Button1Click(Sender: TObject);
begin
  ShowMessage(GetTopLevelDomain('http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/'));
end;

function GetTopLevelDomain(const AURL: string): string;
var
  Index: Integer;
  Temp: string;
begin
  Result := '';

  Temp := Trim(AURL);
  Index := Pos('//', AURL);
  if Index > 0 then
  begin
    Inc(Index, 2);
    Temp := Copy(Temp, Index, Length(Temp) - Index);
  end;

  Index := Pos('/', Temp);
  if Index > 0 then
    Temp := Copy(Temp, 1, Index-1);

  Index := Length(Temp);
  while (Index > 0) and (Temp[Index] <> '.') do
  begin
    Result := Temp[Index] + Result;
    Dec(Index);
  end;
end;

Open in new window

0
 
LVL 24

Expert Comment

by:jimyX
ID: 35046599
procedure TForm1.Button1Click(Sender: TObject);
var
  str:string;
begin
  str:=Memo1.Text;
  repeat
    delete(str,1,pos('<td valign="top">',str)+ length('<td valign="top">')-1);
    showmessage(trim(copy(str,1,pos('</td>',str)-1)));
  until pos('<td valign="top">',Str) <= 0;
end;

Open in new window


Now I lost some points ;-)
EE works this way: All new questions are always posted separately as long as they are not directly related to the original question (or answering them does not provide further clarification for it).
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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

932 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

13 Experts available now in Live!

Get 1:1 Help Now