Solved

String function in delphi

Posted on 2011-03-06
5
425 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
Comment Utility
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
Comment Utility
thanks, it works
0
 

Author Comment

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

thanks
0
 
LVL 32

Expert Comment

by:ewangoya
Comment Utility

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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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 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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now