private static void replace(String str){
String reg="\\s+[^\\s]+\\s+";
Pattern p=Patterncompile(reg);
Matcher m=pmatcher(str);
while(mfind()){
Systemoutprintln(mgroup());
Systemoutprintln("sadf");
}
}
public static void main(String[] args) {
String str=" qi 每个 qxx_dsdf 次12 文明 具";
replace(str);
}
1、按行读,每个换行符是一行
public static String[] split(String str, char separatorChar) {
if (str == null) {
return null;
}
int length = strlength();
if (length == 0) {
return ArrayUtilEMPTY_STRING_ARRAY;
}
List list = new ArrayList();
int i = 0;
int start = 0;
boolean match = false;
while (i < length) {
if (strcharAt(i) == separatorChar) {
if (match) {
listadd(strsubstring(start, i));
match = false;
}
start = ++i;
continue;
}
match = true;
i++;
}
if (match) {
listadd(strsubstring(start, i));
}
return (String[]) listtoArray(new String[listsize()]);
}
使用Stringreplace("", "")方法
String content = "去 掉 空 格";Systemoutprintln(contentreplace(" ", ""));
StringBuffer buffer = new StringBuffer();
int iCharNum = 0;
Reader in = null;
try {
FileInputStream fis = new FileInputStream(objFile);
InputStreamReader isr = new InputStreamReader(fis, encoding);
in = new BufferedReader(isr);
int ch;
while ((ch = inread()) > -1) {
iCharNum += 1;
bufferappend((char) ch);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
eprintStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
eprintStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
} finally {
try {
inclose();
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
contentappend(buffer);
以上就是关于java 怎么用正则表达式提取两个空格之间的字符呢全部的内容,包括:java 怎么用正则表达式提取两个空格之间的字符呢、java读取文件时,空格或换行是各个字符串的分割符,怎么才能将字符串一一读出、用java怎么读取文本字符并去掉中间的空格等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)