ST3VO
asked on
Getting part of a URL
Hi all,
I have a URL that looks like this:
http://vr.myhosting.com/dat/somedirectory/AETA10120/
I need to extract the AETA10120 from the URL not the AETA10120/ <--- fowardslash
then add it to a memo.
Can someone help please?
Thanks
ST3VO
I have a URL that looks like this:
http://vr.myhosting.com/dat/somedirectory/AETA10120/
I need to extract the AETA10120 from the URL not the AETA10120/ <--- fowardslash
then add it to a memo.
Can someone help please?
Thanks
ST3VO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll check it out...thanks :o)
ASKER
Yep...Works perfect!!!! Thanks a million!!! :o)
you might want to add a SL.StrictDelimiter := true in there just to be sure:
SL:=TStringList.Create;
SL.Delimiter := '/';
SL.StrictDelimiter := true;
// etc ...
ASKER
Opps...sorry...got a problem...
when it adds the the memo there seems to be a space at the end or beginning which my program things it's number just the number by also a space character :o/
when it adds the the memo there seems to be a space at the end or beginning which my program things it's number just the number by also a space character :o/
can you explain what you mean, I don't understand.
ASKER
The remaining: AETA10120 is added to a memo....then saved to a file called id.dat.
When reading the id.dat ...it seems to not being reading exactly AETA10120 but probably AETA10120 plus a space somewhere at the beginning or ending because it doesn't recognise the id AETA10120 :o/
I might open another question for this as I have already accepted an answer!
When reading the id.dat ...it seems to not being reading exactly AETA10120 but probably AETA10120 plus a space somewhere at the beginning or ending because it doesn't recognise the id AETA10120 :o/
I might open another question for this as I have already accepted an answer!
>you might want to add a SL.StrictDelimiter := true in there just to be sure:
MerijnB, my D7 has no clue what you are talking about :)
(found the explanation online, apparently a property that was added in D2006...)
ST3VO, no space is added in the code above, this happens at some point later I guess.
To test, I've added a '|' before and after the string when adding it to the memo. You'll see this:
|AETA10120|
so, no space...
procedure TForm1.Button1Click(Sender : TObject);
var
s, testStr:String;
SL: TStringList;
begin
s:='http://vr.myhosting.com/dat/somedirectory/AETA10120/';
SL:=TStringList.Create;
SL.Delimiter := '/';
SL.DelimitedText := s;
testStr:=SL[SL.Count-2];
s:='|'+testStr+'|';
Memo1.Lines.Add(s);
SL.Free;
end;
MerijnB, my D7 has no clue what you are talking about :)
(found the explanation online, apparently a property that was added in D2006...)
ST3VO, no space is added in the code above, this happens at some point later I guess.
To test, I've added a '|' before and after the string when adding it to the memo. You'll see this:
|AETA10120|
so, no space...
procedure TForm1.Button1Click(Sender
var
s, testStr:String;
SL: TStringList;
begin
s:='http://vr.myhosting.com/dat/somedirectory/AETA10120/';
SL:=TStringList.Create;
SL.Delimiter := '/';
SL.DelimitedText := s;
testStr:=SL[SL.Count-2];
s:='|'+testStr+'|';
Memo1.Lines.Add(s);
SL.Free;
end;
Or maybe it's better to test the string after it's been added to the memo:
s:='http://vr.myhosting.com/dat/somedirectory/AETA10120/';
SL:=TStringList.Create;
SL.Delimiter := '/';
SL.DelimitedText := s;
testStr:=SL[SL.Count-2];
Memo1.Lines.Add(testStr);
ShowMessage('|'+Memo1.Line s[0]+'|');
SL.Free;
s:='http://vr.myhosting.com/dat/somedirectory/AETA10120/';
SL:=TStringList.Create;
SL.Delimiter := '/';
SL.DelimitedText := s;
testStr:=SL[SL.Count-2];
Memo1.Lines.Add(testStr);
ShowMessage('|'+Memo1.Line
SL.Free;
ASKER
Cool....works now!!!! Thanks a million...guys!!! :o)
Sorry, I had started to write "don't forget to free the stringlist afterwards", but then I decided to do it myself in the code and forgot to delete the "don't" ;)