Home  |  Delphi .net Home  |  System.IO.Path  |  GetExtension Method
  
GetExtension  
Method  
Returns the Extension value, if present, for a given Path string
Path Class
System.IO NameSpace
CF1.  Function GetExtension ( PathString : String ) : String; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
The GetExtension method returns the extension, including the . prefix character, of the specified PathString, or an empty string if it has no extension (HasExtension = false).
Microsoft MSDN Links
System.IO
System.IO.Path
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Getting the extension of files with an without extensions
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  PathString : String;

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

  if System.IO.Path.HasExtension(PathString)
  then Console.WriteLine('"{0}" has extension "{1}"',
                         PathString,
                         System.IO.Path.GetExtension(PathString))
  else Console.WriteLine('"{0}" has no extension',
                         PathString);

  PathString := 'C:\DelphiBasics';

  if System.IO.Path.HasExtension(PathString)
  then Console.WriteLine('"{0}" has extension "{1}"',
                         PathString,
                         System.IO.Path.GetExtension(PathString))
  else Console.WriteLine('"{0}" has no extension',
                         PathString);

  Console.Readline;
end.
   "C:\DelphiBasics.txt" has extension ".txt"
   "C:\DelphiBasics" has no extension
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author