Avoid repeated concatenation (O(n^2)) in Str.trans