Logo

Programming-Idioms

  • PHP
  • Haskell

Idiom #151 Remove string trailing path separator

Remove last character from string p, if this character is the file path separator of current platform.

Note that this also transforms unix root path "/" into the empty string!

import Data.List (dropWhileEnd)
import System.FilePath (pathSeparator)
p' = dropWhileEnd (== pathSeparator) p
using System.IO;
p.TrimEnd(Path.DirectorySeparatorChar);

New implementation...
< >
programming-idioms.org