Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

String function in delphi

Posted on 2011-03-06
5
Medium Priority
?
446 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 2000 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

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

This is about my first experience with programming Arduino.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
Screencast - Getting to Know the Pipeline

877 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