如何编写20000行的代码,用文件中的逗号替换空格 [英] how to write a code for 20000 lines to replace space with comma in a file
本文介绍了如何编写20000行的代码,用文件中的逗号替换空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
arrunav 25871
elarital 48734
depaal 43212
sujan 23467
我的数据在记事本中高达2000+行,如上图所示,该数据如何用逗号替换空格?
arun,36985
arrunav,25871
elarital,48734
depaal,43212
sujan, 23467
解决方案
尝试:
string data = File.ReadAllText(path);
data = data.Replace( , ,);
File.WriteAllText(路径,数据);
忘记数据! :doh:[/ edit]
在类似unix的shell(例如,Cygwin):
perl -pi.bak -es / /, /G; filename_to_process
在命令提示符(DOS shell)中,假设perl.exe的位置在路径上:
perl.exe -pi.bak -es / /,/ g; filename_to_process
应该这样做......
arun 36985
arrunav 25871
elarital 48734
depaal 43212
sujan 23467
my data is up to 2000+ lines it is in notepad as shown in above for that data how can i replace space with comma?
arun,36985
arrunav,25871
elarital,48734
depaal,43212
sujan,23467
解决方案
Try:
string data = File.ReadAllText(path); data = data.Replace(" ", ","); File.WriteAllText(path, data);
[edit]Forgot the data! :doh:[/edit]
At a unix-like shell (e.g., Cygwin):
perl -pi.bak -e "s/ /,/g;" filename_to_process
In a Command Prompt (DOS shell) assuming the location of perl.exe is on the PATH:
perl.exe -pi.bak -e "s/ /,/g;" filename_to_process
ought to do it...
这篇关于如何编写20000行的代码,用文件中的逗号替换空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文