Solved

Remove last characters of a string

Posted on 2007-11-30
4
2,648 Views
Last Modified: 2012-06-27
hi all,

I have a URL that I need to change.

It looks like this:

http://www.somewebsite/com/35445485448154_2b.jpg

I need to remove the "2b.jpg" at the end and replace it with "1b.jpg"

It's urgent...could you please help?

Thanks

ST3VO
0
Comment
Question by:ST3VO
  • 2
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 20381124
if its' something else you're looking for, give more details.
function update_url(url, s:string):string;

var i:integer;

begin

  i:=pos('_', url);

  assert(i>0);

  delete(url, i+1, length(url));

  result:=url+s;

end;
 

....

update_url('http://www.somewebsite/com/35445485448154_2b.jpg', '1b.jpg');

....

Open in new window

0
 

Author Comment

by:ST3VO
ID: 20381173
Why isn't this working??? Edit box it now being updated!
function update_url(url, s:string):string;

var i:integer;

begin

  i:=pos('_', url);

  assert(i>0);

  delete(url, i+1, length(url));

  result:=url+s;

end;
 

procedure TForm1.Button1Click(Sender: TObject);

var s, new: string;

begin

s:=Edit1.Text;

update_url(s,'1b.jpg');

Edit1.Text:=(s);
 

end;

Open in new window

0
 
LVL 28

Expert Comment

by:2266180
ID: 20381201
update_url is a funciton not a procedure. which means it returns the modified string as a result. basically this allows you to use it nicely in one line like below ;)
procedure TForm1.Button1Click(Sender: TObject);

begin

  Edit1.Text:=update_url(edit2.text,'1b.jpg');

end;

Open in new window

0
 

Author Closing Comment

by:ST3VO
ID: 31411890
Perfect!!! Thanks! :o)
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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

20 Experts available now in Live!

Get 1:1 Help Now