我将这段文本输入到字符串缓冲区中,
857,9/25/14
REEL SCAN,BASIS WT
,0.7600,66067.3,50212.4,61.0
,49.572,-0.3720,0.0000
,111.89,108.28,94.72,106.23
,99.82,83.41
运行此后
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null) {
line = line.replace("REEL SCAN" + "," + "BASIS WT", "");
stringBuffer.append(line.trim());
stringBuffer.append("\n");
}
我明白了
857,9/25/14
,0.7600,66067.3,50212.4,61.0
,49.572,-0.3720,0.0000
,111.89,108.28,94.72,106.23
,99.82,83.41
我如何在同一时间摆脱空白行
857,9/25/14
,0.7600,66067.3,50212.4,61.0
,49.572,-0.3720,0.0000
,111.89,108.28,94.72,106.23
,99.82,83.41
我努力了
line = line.replace("REEL SCAN" + "," + "BASIS WT" + "\n\n", "");
和我在这里发现的其他变化,但没有运气。
我需要的是第二行完全消失了,但是它永远不会是第二行。
最佳答案
也许只是从StringBuffer完全跳过该行
while ((line = bufferedReader.readLine()) != null) {
if(line.contains("REEL SCAN,BASIS WT") {
continue;
}
stringBuffer.append(line.trim());
stringBuffer.append("\n");
}
关于java - Java,删除文本并在stringBuffer中换行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27366285/