Solved

Remove last characters of a string

Posted on 2007-11-30
4
2,636 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:
ciuly earned 500 total points
Comment Utility
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
Comment Utility
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:ciuly
Comment Utility
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
Comment Utility
Perfect!!! Thanks! :o)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

12 Experts available now in Live!

Get 1:1 Help Now