gpt4 book ai didi

string - 用空格替换选项卡

转载 作者:行者123 更新时间:2023-12-03 11:33:10 26 4
gpt4 key购买 nike

我的数据库的文本文件(作业):

'Angola Africa '   
'Burkina Faso Africa'
'Burundi Africa'
...... ()
我想用空格替换这些选项卡。我试过了:
fn main() {    
let data_file = File::open("raw_data2.txt").unwrap();
let reader = BufReader::new(data_file);
let mut sql_commands = OpenOptions::new()
.write(true)
.open("SQL_input.sql")
.unwrap();

for (index, line) in reader.lines().enumerate() {
let Line: String = line.unwrap(); // Ignore errors.
Line = Line.replace(" "," ");
let SQL_query: Vec<&str> = Line.split(' ').collect::<Vec<_>>();
println!("{}. {}", index + 1, Line);
if let Err(e) = writeln!(sql_commands, "{}", SQL_query[0]) {
eprintln!("Couldn't write to file: {}", e);}
}
}
}
replace什么也没做!我还可以做些什么?

最佳答案

在当前代码中,您要用一个空格替换三个空格。没有制表符受到伤害。考虑将" "替换为"\t"

Line = Line.replace("\t"," ");

关于string - 用空格替换选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63872964/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com