Home  |  Delphi .net Home  |  System.IO.Path  |  ChangeExtension Method
ChangeExtension  
Method  
Changes the Extension of the File Name in the specified Path string
Path Class
System.IO NameSpace
CF1.  Function ChangeExtension ( PathString:StringPathString : String; NewExtension : String; ) : String; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
The ChangeExtension method returns a new string that contains the PathString value with its extension changed to NewExtension.
 
If PathString does not contain an extension, the NewExtension is added to it.
Microsoft MSDN Links
System.IO
System.IO.Path
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  PathString : String;

begin
  PathString := 'C:\DelphiBasics.txt';

  Console.WriteLine(PathString);
  Console.WriteLine;
  Console.WriteLine('Changing the extension to ".asm"');
  Console.WriteLine;

  PathString := System.IO.Path.ChangeExtension(PathString, '.asm');

  Console.WriteLine(PathString);

  Console.Readline;
end.
Show full unit code
  C:\DelphiBasics.txt
  
  Changing the extension to ".asm"
  
  C:\DelphiBasics.asm
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author