Solved

Remove last characters of a string

Posted on 2007-11-30
4
2,669 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Connection between libmysql.dll and MySQL Versions 7 113
When I am typing into a TEdit last word repeats 7 147
control image tags in a string ? 12 142
DBCtrlGrid, Delphi, Scroll 8 38
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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