Link to home
Start Free TrialLog in
Avatar of ST3VO
ST3VOFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Remove last characters of a string

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
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ST3VO

ASKER

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

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

Avatar of ST3VO

ASKER

Perfect!!! Thanks! :o)