Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-27-2011, 09:24 AM
Shadow Shadow is offline
Member
 
Join Date: Mar 2011
Posts: 39
Default StringReplace

Briefly, I am building a program that stores files in folders according to the date the program was used; so the folders would obtain the name of the date.

Firstly, onButton click, I put in the StrToDate function to get the date which would be the folder's name. But it is not possible to have '/' in a folder name so I used the StringReplace function to try and replace the '/' with a '-'.

Heres my code:

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  before, after: string;
begin
  before := DateToStr(Date);
  after  := StringReplace(before, '/', '-' [rfReplaceAll]);
  ShowMessage(after);
end;
I compiled the program and got a red highlight error here:
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  before, after: string;
begin
  before := DateToStr(Date);
  after  := StringReplace(before, '/', '-' [rfReplaceAll]);
  ShowMessage(after);
end;
So what would be the problem with my code? Am I not allowed to use forward slashes and hyphens? Or is there simply an error in there? Is there also a better way I can go about doing this?

Thanks in advanced

~Edit~
I followed by the StringReplace tutorial on DelphiBasics; hence the strings, before and after.

Last edited by Shadow; 04-27-2011 at 09:27 AM.
Reply With Quote
  #2  
Old 04-27-2011, 12:14 PM
Shadow Shadow is offline
Member
 
Join Date: Mar 2011
Posts: 39
Default

I figured it out after a while.
Reply With Quote
  #3  
Old 04-27-2011, 07:12 PM
SilverBoy SilverBoy is offline
Member
 
Join Date: Jun 2010
Posts: 46
Default

Code:
var
  before, after: string;
begin
  before := DateToStr(Date);
  after  := StringReplace(before, '/', '-', [rfReplaceAll]);
  ShowMessage(after);
end;
Reply With Quote
  #4  
Old 04-27-2011, 09:02 PM
Shadow Shadow is offline
Member
 
Join Date: Mar 2011
Posts: 39
Default

I see where I went wrong.
Thanks for your reply.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:20 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.