package cn.edu.bjut.chapter2; public class Ipc { public static void main(String[] args) { final char SEPARATOR = '/'; { char section = 'A'; int mainClass = 4; char subclass = 'B'; int mainGroup = 55; int subgroup = 56; String classification = section + String.format("%2s", mainClass).replace(' ', '0') + subclass + String.format("%4s", mainGroup) + SEPARATOR + subgroup; System.out.println(classification); } { String classification = "A04B 55/56"; char section = classification.charAt(0); int mainClass = Integer.parseInt(classification.substring(1, 3)); char subclass = classification.charAt(3); int pos = classification.indexOf(SEPARATOR); int mainGroup = Integer.parseInt(classification.substring(4, pos).trim()); int subgroup = Integer.parseInt(classification.substring(pos + 1)); System.out.println(section + "\t" + mainClass + "\t" + subclass + "\t" + mainGroup + "\t" + subgroup); } } }