導航:首頁 > 編程語言 > java去掉換行

java去掉換行

發布時間:2022-04-05 02:30:30

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」,把這個找出來,然後替換為""就可以了

閱讀全文

與java去掉換行相關的資料

熱點內容
優信二手車解壓後過戶 瀏覽:61
Windows常用c編譯器 瀏覽:778
關於改善國家網路安全的行政命令 瀏覽:833
安卓如何下載網易荒野pc服 瀏覽:654
javainetaddress 瀏覽:104
蘋果4s固件下載完了怎麼解壓 瀏覽:1002
命令zpa 瀏覽:285
python編譯器小程序 瀏覽:944
在app上看視頻怎麼光線調暗 瀏覽:540
可以中文解壓的解壓軟體 瀏覽:592
安卓卸載組件應用怎麼安裝 瀏覽:912
使用面向對象編程的方式 瀏覽:339
程序員項目經理的年終總結範文 瀏覽:929
內衣的加密設計用來幹嘛的 瀏覽:432
淮安數據加密 瀏覽:292
魔高一丈指標源碼 瀏覽:982
松下php研究所 瀏覽:168
c回調java 瀏覽:399
夢幻端游長安地圖互通源碼 瀏覽:745
電腦本地文件如何上傳伺服器 瀏覽:313