Modified countString method in StringTools