格式化字符串-提取中文

时间:2017-01-07 21:02:57   收藏:0   阅读:173

 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、结果

技术分享

 

原文:http://www.cnblogs.com/aGboke/p/6260282.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!