标签:indexof void length 解析 count str div tin sys
@Test public void testStorageImage(){
String titleStem = "年后啊「2454683_1」不好吗"; String titleStem2 = "不太好啊「2454683_1」不对吗「2222683_1」知道了"; //题目里单个解析 int begin = titleStem.indexOf("「"); int end = titleStem.indexOf("」"); String imageName = titleStem.substring(begin+1,end); System.out.println(imageName); //题目里多个解析,解析出问题,先放着,以后处理 String[] imageNames = new String[100 ]; int count = countStr(titleStem2,"「"); for(int i=1;i<=count;i++){ imageNames[i] = getIndexOfJson(titleStem2,i); System.out.println(imageNames[i]); } }
//获取第几个目标字符串 public String getIndexOfJson(String str, int index) { int beginindex = findStrIndex(str, "「", index); int endindex = findStrIndex(str, "」", index); str = str.substring(beginindex + 1, endindex); return str; }
//获取第几个查询到的索引位置 public int findStrIndex(String str, String cha, int num) { int x = str.indexOf(cha); for (int i = 0; i < num - 1; i++) { x = str.indexOf(cha, x + 1); } return x; }
//查询字符串中有几个符号 private int countStr(String str, String sToFind) { int num = 0; while (str.contains(sToFind)) { str = str.substring(str.indexOf(sToFind) + sToFind.length()); num++; } return num; }
标签:indexof void length 解析 count str div tin sys
原文地址:https://www.cnblogs.com/EarlyBridVic/p/12724705.html