Thread: StringReplace
View Single Post
  #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