• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2755
  • Last Modified:

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
0
ST3VO
Asked:
ST3VO
  • 2
  • 2
1 Solution
 
2266180Commented:
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
 
ST3VOAuthor Commented:
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
 
2266180Commented:
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
 
ST3VOAuthor Commented:
Perfect!!! Thanks! :o)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now