zoukankan      html  css  js  c++  java
  • String 和 json 的常用方法

    去除字符串中的汉字:
    String str = "YYY54123上海市";
    String reg = "[u4e00-u9fa5]";
    Pattern pat = Pattern.compile(reg);
    Matcher mat=pat.matcher(str);
    String repickStr = mat.replaceAll("");
    System.out.println(repickStr);

    取出字符串中的汉字:
    String str = "Raaaaa怎取出来0.0111-0.1532";
    String reg = "[^u4e00-u9fa5]";
    str = str.replaceAll(reg, " ").trim();
    System.out.println(str);


    字符串中的,换成、
    String number = "长阳路,江浦路";
    String newNumber = number.replace(",", "、");
    System.out.println(newNumber);

    //去掉字符串头尾:
    String oleStr = "testldld";
    String newStr = oleStr.substring(1, oleStr.length()-1);
    System.out.printf("11111:"+ " "+newStr);

    //json 拼接
    String d="{"username1":"zhangsan","password1":"zhangsan"}";
    net.sf.json.JSONObject json1= net.sf.json.JSONObject.fromObject(d);
    String e="{"username2":"lisi","password2":"lisi"}";
    net.sf.json.JSONObject json2=net.sf.json.JSONObject.fromObject(e);
    net.sf.json.JSONObject json = new net.sf.json.JSONObject();
    json6.putAll(json1);
    json6.putAll(json2);
    System.out.println(json);


    取json字符串 中的jsonArray

    JSONArray data = saveJson.getJSONArray("data");//数组名
    saveJson=data.getJSONObject(0);//第一个json
    String applyNo = saveJson.getString("applyNo");//取出参数

  • 相关阅读:
    Codeforces Round #425 (Div. 2) Problem A Sasha and Sticks (Codeforces 832A)
    bzoj 2301 Problem b
    bzoj 1101 [POI2007]Zap
    bzoj 2005 能量采集
    bzoj 2527 Meteors
    bzoj 2724 [Violet 6]蒲公英
    回顾树状数组
    bzoj 3237 连通图
    bzoj 2733 永无乡
    Codeforces 817C Really Big Numbers
  • 原文地址:https://www.cnblogs.com/lifan12589/p/11711973.html
Copyright © 2011-2022 走看看