Logo

Programming-Idioms

Assign to ext the fragment of the string f after the last dot character, or the empty string if f does not contain a dot.

E.g. "photo.jpg" -> "jpg"

ext must not contain the dot character.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "path/filepath"
import "strings"
ext := strings.TrimPrefix(filepath.Ext(f), ".")
sysutils
ext := ExtractFileExt(f); //contains the dot or is empty string
if (ext <> '') then system.delete(ext,1,1); //removes the leading dot
import os
ext = os.path.splitext(f)[1][1:]
ext = File.extname(f).delete_prefix(".")