Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • D

Idiom #150 Remove trailing slash

Remove the last character from the string p, if this character is a forward slash /

import std.string;
p=p.chomp("/");
import std.stdio : writeln;
import std.algorithm.mutation : stripRight;
auto p = "no_more_slashes///".stripRight!(a => a == '/');
writeln(p); // no_more_slashes
(clojure.string/replace p #"/$" "")

Ensure the regex has a $ at the end!

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