且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何编写20000行的代码,用文件中的逗号替换空格

更新时间:2022-12-28 16:09:48

尝试:

  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...