remove repeat code in stringUtil.js