Logo

Programming-Idioms

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

Idiom #168 Trim suffix

Create string t consisting of string s with its suffix w removed (if s ends with w).

  i = index(s,w,back=.true.) - 1
  if (i == len(s) - len(w) ) then
     allocate (t, source=s(:i))
  else
     allocate (t, source=s)
  end if

This assumes that t is unallocated before.
using System;
string t = s.TrimEnd(w);

New implementation...
programming-idioms.org