//去除首尾的空格
private static String claerTrim(String str) {
String st = "";
int flag = 0;
int first=0,last=str.length();
for(int i=0;i<str.length();i++){
char ch = str.charAt(i);
if(ch == ' '){
continue;
}else{
first = i;
break;
}
}
for(int i=str.length()-1;i>0;i--){
char ch = str.charAt(i);
if(ch == ' '){
continue;
}else{
last = i;
break;
}
}
System.out.println(first);
System.out.println(last);
while(first<=last){
char ch = str.charAt(first);
st = st + ch + "";
System.out.println(st);
first++;
}
//System.out.println(st);
return st;
}
//获取上传文件名 "D:\\20120512\\day12\\Demo1.java"。
public static String getFileName2( String path ){
return path.substring( path.lastIndexOf("\\") + 1 );
}
}
// 求一个子串在整串中出现的次数
public static int getCount( String src , String tag ){
// 0. 定义索引变量和统计个数的变量
int index = 0;
int count = 0;
// 1. 写循环判断
while ( ( index = src.indexOf(tag) ) != -1 ) // jackjava
{
// 2. 求字串
System.out.println( src );
src = src.substring( index + tag.length() ); // index 4 + 4 = 8
System.out.print( src.length() + " : " + index + " : " + tag.length() );
// 3. 累加
count++;
}
return count;
}