Often that may be OK, but not always. For removeSuffix() I have used 
strutils.replace() sometimes as a substitute, but that is not always the best 
solution.

So I was just thinking about other solutions. An apply template seems to work:
    
    
    import strutils
    
    template apply(x: typed; f: typed; par: typed): untyped =
      var h = x
      f(h, par)
      h
    
    const
      Name = "manual.txt"
      Doc = Name.replace(".txt") & ".html"
      #Doc2 = Name.removeSuffix(".txt")
      Doc3 = apply(Name, removeSuffix, ".txt")
      Doc4 = Name.apply(removeSuffix, ".txt")
    
    echo Doc
    echo Doc3
    echo Doc4
    
    
    Run
    
    
    manual.html
    manual
    manual
    
    
    Run

Maybe there are even better solutions?

(Of course I understand why removeSuffix() works in place, while replace not: 
The code of replace needs a temporary string as buffer, as the replacement can 
be larger, so it makes sense to return that buffer. removeSuffix() can work in 
place, so it does this. But sometimes a proc with result like suffixRemoved() 
is what one wants.)

Reply via email to