[github-339] Add extra methods to StringUtil and refactor some code to use them. Thanks to XenoAmess. This closes #339