使用PowerShell,我想用一个替换[MYID]给定文件中的所有确切事件MyValue.最简单的方法是什么?
我正在尝试使用带有UTF8编码的VB.Net创建一个文本文件,没有BOM.任何人都可以帮助我,怎么做?
我可以用UTF8编码写文件但是,如何从中删除字节顺序标记?
edit1:我尝试过像这样的代码;
Dim utf8 As New UTF8Encoding()
Dim utf8EmitBOM As New UTF8Encoding(True)
Dim strW As New StreamWriter("c:\temp\bom\1.html", True, utf8EmitBOM)
strW.Write(utf8EmitBOM.GetPreamble())
strW.WriteLine("hi there")
strW.Close()
Dim strw2 As New StreamWriter("c:\temp\bom\2.html", True, utf8)
strw2.Write(utf8.GetPreamble())
strw2.WriteLine("hi there")
strw2.Close()
Run Code Online (Sandbox Code Playgroud)
1.html仅使用UTF8编码创建,2.html使用ANSI编码格式创建.
简化方法 - http://whatilearnttuday.blogspot.com/2011/10/write-text-files-without-byte-order.html
我有一个我使用PowerShell修改的XML配置文件,当我使用Xml.Save保存文件时,它会更改编码类型.
当我打开ORIGINAL文件时,我试图在Notepad ++中编辑,编码类型被列为"没有BOM的UTF-8".当我在Notepad ++中使用Xml.Save编辑打开文件时,编码类型被简单地列为"UTF-8".这会导致使用此文件的程序错误地说它无法解析为配置属性.
如果我在Notepad ++中打开EDITED文件,请将编码类型更改为"UTF-8 without BOM",然后保存文件.然后程序将运行而不会出错.
Xml.Save保存文件时,如何强制和/或指定使用"无BOM的UTF-8"编码类型?
我已经尝试了不同的方法来转换和保存文件,但Xml.Save似乎默认为"UTF-8"enconding类型.
$xml = New-Object -TypeName XML
$xml.Load($file)
$xml.configuration.config.option = $newValue
$xml.Save($file)
Run Code Online (Sandbox Code Playgroud)