返回列表 发帖

[问题求助] 求助PowerShell生成UTF-8 LF编码不带BOM

param([strinG]$file); #修改前的文件
$file1 = [io.fileinfo]$file;
$file2 = ".\2.txt"
(Get-Content $file -ReadCount 0)-replace' Mobile / Max-Q','Max-Q'-replace'Mobile / ',''|Set-Content -encoding UTF8 $file2COPY
UTF-8 LF 不是UTF-8 CR+LF
师从Jet Chan、mdyblog、WHY、Batcher,追求实用与效率。以解决问题为本,专注实践,保持学习,持续精进。

param([strinG]$file);                #修改前的文件
$file1 = [io.fileinfo]$file;
$file2 = ".\2.txt";
$UTF8NoBom = New-Object System.Text.UTF8Encoding $false;
$str = [IO.File]::ReadAllText($file, [Text.Encoding]::Default);
$str = $str -replace ' Mobile / Max-Q','Max-Q' -replace 'Mobile / ' -replace '\r\n', "`n";
[IO.File]::WriteAllText($file2, $str, $UTF8NoBom);COPY
1

评分人数

    • smss: 中秋快乐技术 + 1

TOP

返回列表