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

人气:901 发布:2022-09-22 标签: perl

问题描述

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

723