As part of an attempt to improve computer-based test scoring on traditional grid answer sheets, which are used by 76.36% of interrogated schools in Thailand, this paper proposes an algorithm to segment the problematic handwritten-style student identification number. The method used is based on profile features supported by digit width-height ratio analysis. Non-touching digits are segmented by vertical histograms and the flood fill algorithm. Touching digits are segmented by considering the distances between upper and lower profiles as well as the derivatives of consecutive points of their profiles. Among 231 six-digit image sequences, the average segmentation accuracy rate was 98.20%, which is considered satisfactory. The results showed that an increased number of consecutive cursive digits decreased the segmentation accuracy, and was significant from 5 connecting digits.