标签:for str first private 代码 取字符串 compile 次数 while
/**
* 获取第i个位置上的子串
*
* @param string
* @param i
* @param str
* @return
*/
public static int getIndex(String string, int i, String str) {
Matcher slashMatcher = Pattern.compile(str).matcher(string);
int mIdx = 0;
while (slashMatcher.find()) {
mIdx++;
if (mIdx == i) {
break;
}
}
return slashMatcher.start();
}
/**
* 获取pattern1和pattern2之间的子串
*
* @param src
* @param pattern1
* @param pattern2
* @return
*/
public String getAttribute(String src, String pattern1, String pattern2) {
String result = null;
int beginindex = 0;
int endindex = 0;
beginindex = src.indexOf(pattern1);
endindex = src.indexOf(pattern2);
//这里的9,跟3 两个数字,是根据解析的标签长度制定的,
result = src.substring(beginindex+8, endindex );
return result;
}
/**
* 统计子串出现的次数
*
* @param str
* @param sToFind
* @return
*/
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;
}
//根据时间Date获取字符串String格式的数据
public String getFisrtDayOfMonth(Date date){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String firstDayOfMonth = sdf.format(date.getTime());
return firstDayOfMonth;
}
//根据String字符串yyyy-MM-dd HH:mm:ss格式数据,拼接成数字字符串
public String getIdstrs(String time){
String result = "";
String[] two = time.split(" ");
String[] one = two[0].split("-");
String[] three = two[1].split(":");
result+=one[0]+one[1]+one[2]+three[0]+three[1]+three[2]+"";
return result;
}
标签:for str first private 代码 取字符串 compile 次数 while
原文地址:https://www.cnblogs.com/Koaler/p/12210999.html