This is from a long time ago, but still fun:
Sometimes simple things in life are hard do remember.
For instance, I always forgot if a file extension parameter should have a dot in it or not.
Normally it should!
But for clearing an extension, you should use a blank string.
Be aware though that empty extensions look differently depending where in the process you look at them:
C# example:
using System; using System.IO; public class Test { public static void Main() { string extensionLess = Path.ChangeExtension(@"C:\mydir\myfile.com.extension", ""); Console.WriteLine(extensionLess); string extension = Path.GetExtension(extensionLess); Console.WriteLine(extension); } }
Outputs:
C:\mydir\myfile.com.
Delphi example:
program Demo; {$APPTYPE CONSOLE} uses SysUtils; var extensionLess: string; extension: string; begin extensionLess := ChangeFileExt('C:\mydir\myfile.com.extension', ''); Writeln(extensionLess); extension := ExtractFileExt(extensionLess); Writeln(extension); end.
Outputs:
C:\mydir\myfile.com .com
Don’t you love differences in your platforms :)
–jeroen