replaced character searching while loop by Range.each