Icon EnsureFileExt

Unit: WebCore

Available In: Client and Server Applications

function EnsureFileExt(const Value: String; const OldExt: String;
                       const NewExt: String): String

The EnsureFileExt function is very similar to the ChangeFileExt function. However, instead of just changing the file extension to the new file extension, the function first checks the existing file extension to ensure that it matches the old file extension:
  • If the existing file extension matches the old file extension, then the file extension is changed to the new file extension.


  • If the existing file extension does not match the old file extension, then the new file extension is appended to the string input parameter.
The string input parameter can contain both a path and a file name or just a file name, but the file name should include a file extension. The specified file extension should include the period (.) file extension delimiter. The return value will be a string containing the original path and/or file name with the new file extension.

Examples

X := EnsureFileExt('https://www.elevatesoft.com/index.html','.html','.js');  // X is 'https://www.elevatesoft.com/index.js'
Image