zoukankan      html  css  js  c++  java
  • 格式化字符串-提取中文

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

  • 相关阅读:
    web测试学习大纲
    Python语言编程基础
    python文件IO
    Python 正则表达式
    python官网导航翻译
    python常用库
    python连接数据库
    sublime与python交互
    selenium连接浏览器方式
    sublime中运行python时编码格式问题
  • 原文地址:https://www.cnblogs.com/aGboke/p/6260282.html
Copyright © 2011-2022 走看看