Solved

String function in delphi

Posted on 2011-03-06
5
438 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
[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
  • 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:Ephraim Wangoya
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Part One of the two-part Q&A series with MalwareTech.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

623 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