A. java中怎麼處理多餘的回車符
JAVA中去掉空格
1. String.trim()
trim()是去掉首尾空格
2.str.replace(" ", ""); 去掉所有空格,包括首尾、中間
復制代碼 代碼如下:String str = " hell o ";
String str2 = str.replaceAll(" ", "");
System.out.println(str2);
3.或者replaceAll(" +",""); 去掉所有空格
4.str = .replaceAll("\\s*", "");
可以替換大部分空白字元, 不限於空格
\s 可以匹配空格、製表符、換頁符等空白字元的其中任意一個 您可能感興趣的文章:java去除字元串中的空格、回車、換行符、製表符的小例子
B. 如何從一個字元串中刪除所有換行符
windows字元串中的換行符="\r\n"
replaceAll(yourString,"\r\n","");
public static String replaceAll(String str, String old, String news)
{
if(str == null)
return str;
int begin = 0;
int idx = 0;
int len = old.length();
StringBuffer buf = new StringBuffer();
while((idx = str.indexOf(old, begin)) >= 0)
{
buf.append(str.substring(begin, idx));
buf.append(news);
begin = idx + len;
}
return new String(buf.append(str.substring(begin)));
}
C. Java如何去除字元串中的空格、回車、換行符、製表符
1.去除空格:s = s.replace(‘\\s’,); 2.去除回車:s = s.replace(‘\n’,); 這樣也可以把空格和回車去掉,其他也可以照這樣做。 註:\n 回車(\u000a) \t 水平製表符(\u0009) \s 空格(\u0008)\n 換行 將游標移動到下一行第一格 相當於平時用的回車 \r 回車 將游標移動到當前行第一格}
D. java中怎麼替換掉回車換行符
java中替換回車換行符,如果是字元串的話,你可以使用string.replace函數來進行替換.
E. 怎麼去掉換行 - Java
把輸出結果的\r\n替換成「」不就行了
F. java 去掉回車符
在程序同一目錄下建a.txt文本文件測試。
import java.io.*;
class A
{
public static void main(String args [])
{
String context=null;
StringBuffer contextbuffer = new StringBuffer("");
String line = null;
try
{
FileReader fr = new FileReader("./a.txt");
BufferedReader br = new BufferedReader(fr);
while ((line = br.readLine()) != null)
{
contextbuffer.append(line);
}
br.close();
context = contextbuffer.toString();
FileWriter fw = new FileWriter("./a.txt",false);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(context);
bw.flush();
bw.close();
}
catch (Exception e) { }
}
}
G. java 去掉txt里的空格和回車符(也就是換行符)代碼怎麼寫
String filePath = "D://111//11.txt";
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath)));
while((str=br.readLine())!=null) {
String s =str;
s.replace("\r","");
s.replace("\t","");
}
H. java 去除換行符號
String str2="abcd\nabcd";
System.out.println(str2);
str1=str2.replaceAll("\n", "");
System.out.println(str1);
I. 在線求助,去掉JAVA字元串中間的換行
for循環遍歷字元串,length()取得最大索引,charAt(int index)取出字元判斷是否為\r\n是的話replace(old char,"")。
J. java怎麼把字元串後面的回車去掉
回車符號一般都是「\n」,把這個找出來,然後替換為""就可以了