The intention was to make a correct preallocation and the fill it without needing to extend the string or reshuffle its content. It would be good to gain more insight into how the size is calculated. Criteria for evaluating code is not only code size but memory and time efficiency, and efficiency in writing and maintaining the code.