Logo

Programming-Idioms

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

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Haskell 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 "strings"
p = strings.TrimSuffix(p, "/")
if (p.endsWith("/")) {
    p = p.substring(0, p.length() - 1);
}
p = p.replaceAll("/$", "");
p.chomp!("/")
uses SysUtils;
begin
  AllowDirectorySeparators := AllowDirectorySeparators + ['/'];
  p := ExcludeTrailingPathDelimiter(p);
end;
var
  Len: Integer;
begin
  Len := Length(p);
  if (Len > 0) and (p[Len] = '/') then Delete(P, Len, 1);
end;
p = p.TrimEnd('/');
import std.stdio : writeln;
import std.algorithm.mutation : stripRight;
auto p = "no_more_slashes///".stripRight!(a => a == '/');
writeln(p); // no_more_slashes
import std.string;
p=p.chomp("/");
p = p.rstrip("/")
if p.ends_with('/') { p.pop(); }
$p = rtrim($p, '/');
const slashscrape = p => (
  p.slice (-1) === '/' ?
    p.slice (0, -1) :
    p
)
$p =~ s{/$}{};
p.stripSuffix("/")
program x
character(len=:),allocatable :: string
integer :: ii
string='my string/'
ii=len(string)
string=trim(merge(string(:ii-1)//' ',string,string(ii:ii).eq.'/'))
write(*,*)string
end program x
 if('/' == s.back())
  s.pop_back();
p = p.chomp("/")
removeTrailingSlash([$/]) -> [];
removeTrailingSlash([]) -> [];
removeTrailingSlash([Ch | Rest]) ->
        [Ch] ++ removeTrailingSlash(Rest).
if (p.endsWith("/")) p = p.substring(0, p.length - 1);
def main(string), do: String.replace_suffix(string, "/", "")
(defn remove-ending-slash
  [p]
  (if (clojure.string/ends-with? p "/")
    (subs p 0 (dec (count p)))
    s))
(clojure.string/replace p #"/$" "")
{ local $/='/'; chomp $p }