[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 ivor 于 2022-7-31 18:10 编辑
  1. #&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit
  2. $num=0;$tmp=''
  3. get-content a.txt | %{
  4.    
  5.     [char[]]$_ | %{
  6.         if($_ -eq 'a'){
  7.             $num++
  8.             $tmp += $_+$num
  9.         }else{
  10.         $tmp += $_
  11.         }
  12.     }
  13.     $tmp+= "`r`n"
  14.    
  15. }
  16. Out-File -FilePath b.txt -InputObject $tmp
复制代码
#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

回复  ivor


    如果有中文会乱码呀,如果替换ab就会失效
omIyteeee 发表于 2022-7-31 18:52
  1. #&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit
  2. $num=0;$tmp=''
  3. get-content a.txt  -Encoding UTF8 | %{
  4.    
  5.     [char[]]$_ | %{
  6.         if($_ -eq 'a'){
  7.             $num++
  8.             $tmp += $_+$num
  9.         }else{
  10.         $tmp += $_
  11.         }
  12.     }
  13.     $tmp+= "`r`n"
  14.    
  15. }
  16. Out-File -FilePath b.txt -InputObject $tmp
复制代码
#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

返回列表