話很少說,直接上代碼java
import java.util.ArrayList;面試
import java.util.HashMap;segmentfault
import java.util.List;架構
import java.util.Map;spa
import java.util.regex.Pattern;blog
public class StringUtil {開發
static int varlen1;rem
static int varlen2;字符串
static String varstr1;get
static String varstr2;
static String varstr3;
private static Map<String,String> mapMonth =null;
static{
mapMonth = new HashMap<>();
mapMonth.put("Jan", "01");
mapMonth.put("Feb", "02");
mapMonth.put("Mar", "03");
mapMonth.put("Apr", "04");
mapMonth.put("May", "05");
mapMonth.put("Jun", "06");
mapMonth.put("Jul", "07");
mapMonth.put("Aug", "08");
mapMonth.put("Sep", "09");
mapMonth.put("Oct", "10");
mapMonth.put("Nov", "11");
mapMonth.put("Dec", "12");
}
public static String[] getAllTtype(){
return allTtype;
}
/**
*/
public static int indexCounts(String sourceStr,String indexStr){
varlen1 = sourceStr.length();
varlen2 = indexStr.length();
int i=0;//字符串下標
int n=0;//某字符串在指定字符串中的個數
while (i< varlen1){
varstr1 = sourceStr.substring(i, i);//substr(sourceStr,i,1);
varstr2 = indexStr.substring(1,1);//獲取指定用於截串的字符串的第一個字符
if(varstr1.equals(varstr2)){
if(i+varlen2<=varlen1){//判斷字符下標
if(indexStr.equals(sourceStr.substring(i, i+varlen2))){
n++;
i=i+varlen2;
}
}
}
i++;
}
return n+1;
}
/**
*/
public static int indexStrCounts(String sourceStr,String indexStr){
varlen1 = sourceStr.length();
varlen2 = indexStr.length();
int i=0;//字符串下標
int n=0;//某字符串在指定字符串中的個數
while (i< varlen1){
varstr1 = sourceStr.substring(i, i);//substr(sourceStr,i,1);
varstr2 = indexStr.substring(1,1);//獲取指定用於截串的字符串的第一個字符
if(varstr1.equals(varstr2)){
if(i+varlen2<=varlen1){//判斷字符下標
if(indexStr.equals(sourceStr.substring(i, i+varlen2))){
n++;
i=i+varlen2;
}
}
}
i++;
}
return n;
}
/** 是不是整數
*/
public static boolean isNumeric(String strNum){
boolean boo = strRegular(strNum,0,9);
int cou = indexCounts(strNum,".");
if(boo){
return boo;
}else{
if(cou==1){
return false;
}else if(cou==2){
String endNum = indexOf(strNum, ".", 2);
boolean bo = strRegular(endNum,0,9);
if(bo){
Integer in = new Integer(endNum);
if(in==0){
return true;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}
/*if(!boo){
}*/
// return pattern.matcher(strNum).matches();
}
public static boolean strRegular(String strNum,int startNum,int endNum){
Pattern pattern = Pattern.compile("^-?["+startNum+"-"+endNum+"]*");
return pattern.matcher(strNum).matches();
} }
若是你在最近的開發生涯中遇到了問題或者是想提高本身,歡迎閱讀個人文章。
大廠面試題、架構核心技術分享,解決99%的架構師都遇到的問題。
連接:https://segmentfault.com/a/11...