Programming-Idioms

Implementation
C#

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

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

Implementation edit is for fixing errors and enhancing with metadata.

Instead of changing the code of the snippet, consider creating another C# implementation.

Other implementations
import "fmt"
import "os"
import "strings"
sep := fmt.Sprintf("%c", os.PathSeparator)
p = strings.TrimSuffix(p, sep)
import "fmt"
import "path/filepath"
import "strings"
sep := fmt.Sprintf("%c", filepath.Separator)
p = strings.TrimSuffix(p, sep)
p.chomp!("/")
SysUtils
begin
  p := ExcludeTrailingPathDelimiter(p);
end.
LazFileUtils
begin
  p := ChompPathDelim(p);
end.
import std.string,
import std.path;
p = p.chomp(dirSeparator);
import os
if p.endswith(os.sep):
    p = p[:-1]
let p = if ::std::path::is_separator(p.chars().last().unwrap()) {
    &p[0..p.len()-1]
} else {
    p
};
use File::Spec qw();
chomp $p, File::Spec->catdir('');
if string.sub(p, -1, -1) == "/" then
	p=string.sub(p, 1, -2)
end
let p = p.strip_suffix(std::path::is_separator);