格式化字符串-提取中文
1、原来的String
{'info':[{'menuId':'193','menuName':'家装建材'},{'menuId':'194','menuName':'家纺'},{'menuId':'176','menuName':'手机通讯'},{'menuId':'178','menuName':'手机配件'}]}
要求: 家装建材,家纺,手机通讯,手机配件
/** * 格式化字符串 * @param str * @return */ public String SubString(String str){ String substrZyhy=""; Matcher matcher = Pattern.compile("([\u4e00-\u9fa5]+)").matcher(str); while (matcher.find() ) { substrZyhy+= matcher.group(0)+","; } return substrZyhy; }
//测试代码 public static void main(String[] args) { String str=(" {'info':[{'menuId':'193','menuName':'家装建材'},{'menuId':'194','menuName':'家纺'},{'menuId':'176','menuName':'手机通讯'},{'menuId':'178','menuName':'手机配件'}]}"); String substrZyhy=""; Matcher matcher = Pattern.compile("([\u4e00-\u9fa5]+)").matcher(str); while (matcher.find() ) { substrZyhy+= matcher.group(0)+","; } System.out.println(substrZyhy); }
2、结果