PS1文件的正确编码是什么 [英] What is the correct encoding for PS1 files
问题描述
我正在一系列PS1和Amp上进行一些文本流处理.PSM1文件,我遇到了一些带有智能引号和破折号的问题(从不,永远不要从MS Scripting Guy博客中剪切和粘贴代码).我发现问题是编码,所以我看了看,发现文件都有ASCII&UTF8,但是我的时髦文字当然都存在问题.因此,我做了一些替换工作,并且可以正常工作,但是我想知道是否不应该对一种编码进行标准化,如果可以,那么应该对哪一种进行标准化?
I am doing some text stream processing on a series of PS1 & PSM1 files, and I ran into some issues with smart quotes and em-dashes (never, NEVER, cut and paste code from MS Scripting Guy blog). I figured the issue was encoding so I looked, and I have files of both ASCII & UTF8, but of course both have issues with my funky text. So I have done some replacements, and I have that working, but I wonder if I shouldn't also standardize on one encoding, and if so, which one?
推荐答案
虽然不能直接回答您的问题,但是您可能会发现它很有用,我写了一个工具来处理PS和SQL脚本,但很快发现有人在粘贴从他们的电子邮件中弄了很多东西.我必须实施它来纠正所有问题,并且应该得到所有结果:
Not a direct answer to your question but you may find it useful nonetheless, I have a tool I wrote to handle PS and SQL scripts but quickly found people were pasting from their emails which screwed a ton of stuff. I had to implement this to correct it all, and it should get everything:
if ($code.IndexOf([Char]0x2013) -gt -1) { $code = $code.Replace(([Char]0x2013).ToString(), "--") } # en dash
if ($code.IndexOf([Char]0x2014) -gt -1) { $code = $code.Replace(([Char]0x2014).ToString(), "-") } # em dash
if ($code.IndexOf([Char]0x2015) -gt -1) { $code = $code.Replace(([Char]0x2015).ToString(), "-") } # horizontal bar
if ($code.IndexOf([Char]0x2017) -gt -1) { $code = $code.Replace(([Char]0x2017).ToString(), "_") } # double low line
if ($code.IndexOf([Char]0x2018) -gt -1) { $code = $code.Replace(([Char]0x2018).ToString(), "`'") } # left single quotation mark
if ($code.IndexOf([Char]0x2019) -gt -1) { $code = $code.Replace(([Char]0x2019).ToString(), "`'") } # right single quotation mark
if ($code.IndexOf([Char]0x201a) -gt -1) { $code = $code.Replace(([Char]0x201a).ToString(), ",") } # single low-9 quotation mark
if ($code.IndexOf([Char]0x201b) -gt -1) { $code = $code.Replace(([Char]0x201b).ToString(), "`'") } # single high-reversed-9 quotation mark
if ($code.IndexOf([Char]0x201c) -gt -1) { $code = $code.Replace(([Char]0x201c).ToString(), "`"") } # left double quotation mark
if ($code.IndexOf([Char]0x201d) -gt -1) { $code = $code.Replace(([Char]0x201d).ToString(), "`"") } # right double quotation mark
if ($code.IndexOf([Char]0x201e) -gt -1) { $code = $code.Replace(([Char]0x201e).ToString(), "`"") } # double low-9 quotation mark
if ($code.IndexOf([Char]0x2026) -gt -1) { $code = $code.Replace(([Char]0x2026).ToString(), "...") } # horizontal ellipsis
if ($code.IndexOf([Char]0x2032) -gt -1) { $code = $code.Replace(([Char]0x2032).ToString(), "`"") } # prime
if ($code.IndexOf([Char]0x2033) -gt -1) { $code = $code.Replace(([Char]0x2033).ToString(), "`"") } # double prime
if ($code.IndexOf([Char]0x0009) -gt -1) { $code = $code.Replace(([Char]0x0009).ToString(), " ") } # tab
这篇关于PS1文件的正确编码是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!