set "fileIn=C:\LOCATION\Client_List_%DDMMYYYY%.csv"
set "fileOu=C:\LOCATION\Client_List_%DDMMYYYY%.csv"
powershell -c "(gc '%fileIn%').Replace('‘‘','').Replace('’’','')|Out-File '%fileOu%'"
這奇怪撇’
是U+2019
右單引號,按說收盤報價。它可以與一個不同的開放報價配對。在上例中,‘
是U+2018
左單引號。
Get-Help 'about_Quoting_Rules'
說
引號用於指定文本字符串。您可以在單引號('
)或雙引號 ("
)中包含 一個字符串。
事實上,PowerShell中接受兩個不同套報價:
據我所知,所有這些引號存在於大多數Windows ANSI代碼頁(1252,1250,1257,1253,1251,1254,1255,1256,1258),所以他們可以從字面上ANSI
使用 - 保存.bat
腳本 - 除後者引號外‛
U+201B
單個高反轉9引號。在這種情況下,使用$([char]0x201B)
代替'‛‛'
如下:
rem cast [char] to `[string]` ↓↓↓↓↓↓↓↓
powershell -c "(gc '%fileIn%').Replace([string]$([char]0x201B) , '')"
rem ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
或如下:
rem [char] can't be empty so specify `[string]` ↓↓↓↓↓↓↓↓
powershell -c "(gc '%fileIn%').Replace($([char]0x201B) , [string]'')"
rem ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
分析和解釋
接着PowerShell代碼片斷示出了從Unicode數據庫的摘錄(字符名稱與Quotation Mark
結束或含有Apostrophe
):
PS D:> 0x22,0x27,0x00AB,0x00BB,0x2018,0x2019,0x201A,0x201B,0x201C,0x201D,0x201E,0x201F,
0x2039,0x203A,0x2E42,0x301D,0x301E,0x301F,0x055A | Get-CharInfo | Format-Table -AutoSize
Char CodePoint Category Description
---- --------- -------- -----------
" U+0022 OtherPunctuation Quotation Mark
' U+0027 OtherPunctuation Apostrophe
« U+00AB InitialQuotePunctuation Left-Pointing Double Angle Quotation Mark
» U+00BB FinalQuotePunctuation Right-Pointing Double Angle Quotation Mark
‘ U+2018 InitialQuotePunctuation Left Single Quotation Mark
’ U+2019 FinalQuotePunctuation Right Single Quotation Mark
‚ U+201A OpenPunctuation Single Low-9 Quotation Mark
‛ U+201B InitialQuotePunctuation Single High-Reversed-9 Quotation Mark
「 U+201C InitialQuotePunctuation Left Double Quotation Mark
」 U+201D FinalQuotePunctuation Right Double Quotation Mark
„ U+201E OpenPunctuation Double Low-9 Quotation Mark
‟ U+201F InitialQuotePunctuation Double High-Reversed-9 Quotation Mark
‹ U+2039 InitialQuotePunctuation Single Left-Pointing Angle Quotation Mark
› U+203A FinalQuotePunctuation Single Right-Pointing Angle Quotation Mark
⹂ U+2E42 OtherNotAssigned Undefined
〝 U+301D OpenPunctuation Reversed Double Prime Quotation Mark
〞 U+301E ClosePunctuation Double Prime Quotation Mark
〟 U+301F ClosePunctuation Low Double Prime Quotation Mark
՚ U+055A OtherPunctuation Armenian Apostrophe
(從修改的Get-CharInfo
cmdlet輸出。)原始Get-CharInfo
模塊可從http://poshcode.org/5234下載。
下一頁PowerShell腳本上述結果完成了由顯示報價的一些有效的(在我的語言環境無效)組合:
$arrSingleQuotes =
''' U+0027 Apostrophe ''' ,
‘‘‘ U+2018 Left Single Quotation Mark ‘‘‘ ,
’’’ U+2019 Right Single Quotation Mark ’’’ ,
‚‚‚ U+201A Single Low-9 Quotation Mark ‚‚‚ ,
‛‛‛ U+201B Single High-Reversed-9 Quotation Mark ‛‛‛ ,
‘‘‘ U+2018 (Left/Right) Single Quotation Mark U+2019 ’’’ ,
’’’ U+2019 (Right/Left) Single Quotation Mark U+2018 ‘‘‘
'$arrSingleQuotes (any combination)'
$arrSingleQuotes
$arrDoubleQoutes =
""" U+0022 Quotation Mark """ ,
「「「 U+201C Left Double Quotation Mark 「「「 ,
」」」 U+201D Right Double Quotation Mark 」」」 ,
„„„ U+201E Double Low-9 Quotation Mark „„„ ,
「「「 U+201C (Left/Right) Double Quotation Mark U+201D 」」」 ,
」」」 U+201D (Right/Left) Double Quotation Mark U+201C 「「「
'$arrDoubleQoutes (any combination)'
$arrDoubleQoutes
$noQuotes = @"
« U+00AB Left-Pointing Double Angle Quotation Mark
» U+00BB Right-Pointing Double Angle Quotation Mark
‟ U+201F Double High-Reversed-9 Quotation Mark
⹂ U+2E42 DOUBLE LOW-REVERSED-9 QUOTATION MARK
‹ U+2039 Single Left-Pointing Angle Quotation Mark
› U+203A Single Right-Pointing Angle Quotation Mark
〝 U+301D Reversed Double Prime Quotation Mark
〞U+301E Double Prime Quotation Mark
〟U+301F Low Double Prime Quotation Mark
՚ U+055A Armenian Apostrophe
"@
'$noQuotes'
$noQuotes
輸出:
PS D:> D:\PShell\SO\41488245_quotes.ps1
$arrSingleQuotes (any combination)
' U+0027 Apostrophe '
‘ U+2018 Left Single Quotation Mark ‘
’ U+2019 Right Single Quotation Mark ’
‚ U+201A Single Low-9 Quotation Mark ‚
‛ U+201B Single High-Reversed-9 Quotation Mark ‛
‘ U+2018 (Left/Right) Single Quotation Mark U+2019 ’
’ U+2019 (Right/Left) Single Quotation Mark U+2018 ‘
$arrDoubleQoutes (any combination)
" U+0022 Quotation Mark "
「 U+201C Left Double Quotation Mark 「
」 U+201D Right Double Quotation Mark 」
„ U+201E Double Low-9 Quotation Mark „
「 U+201C (Left/Right) Double Quotation Mark U+201D 」
」 U+201D (Right/Left) Double Quotation Mark U+201C 「
$noQuotes
« U+00AB Left-Pointing Double Angle Quotation Mark
» U+00BB Right-Pointing Double Angle Quotation Mark
‟ U+201F Double High-Reversed-9 Quotation Mark
⹂ U+2E42 DOUBLE LOW-REVERSED-9 QUOTATION MARK
‹ U+2039 Single Left-Pointing Angle Quotation Mark
› U+203A Single Right-Pointing Angle Quotation Mark
〝 U+301D Reversed Double Prime Quotation Mark
〞U+301E Double Prime Quotation Mark
〟U+301F Low Double Prime Quotation Mark
՚ U+055A Armenian Apostrophe
注意⹂ U+2E42 DOUBLE LOW-REVERSED-9 QUOTATION MARK
存在於統一數據庫並在PowerShell ISE中正確呈現。
附錄:我發現了更多的引號考生(只顯示結果從腳本Excerpt_From_UnicodeDataTxt.ps1
獲得):
PS > $x = .\tests\Excerpt_From_UnicodeDataTxt.ps1 -SearchString "Quotation|Apostrophe" |
Where-Object {$_.Category -match 'Punctuation'}
PS > $x.Count
23
PS > $x
Char CodePoint Category Description
---- --------- -------- -----------
" U+0022 Po-OtherPunctuation Quotation Mark
' U+0027 Po-OtherPunctuation Apostrophe
« U+00AB Pi-InitialQuotePunctuation Left-Pointing Double Angle Quotation Mark
» U+00BB Pf-FinalQuotePunctuation Right-Pointing Double Angle Quotation Mark
՚ U+055A Po-OtherPunctuation Armenian Apostrophe
‘ U+2018 Pi-InitialQuotePunctuation Left Single Quotation Mark
’ U+2019 Pf-FinalQuotePunctuation Right Single Quotation Mark
‚ U+201A Ps-OpenPunctuation Single Low-9 Quotation Mark
‛ U+201B Pi-InitialQuotePunctuation Single High-Reversed-9 Quotation Mark
「 U+201C Pi-InitialQuotePunctuation Left Double Quotation Mark
」 U+201D Pf-FinalQuotePunctuation Right Double Quotation Mark
„ U+201E Ps-OpenPunctuation Double Low-9 Quotation Mark
‟ U+201F Pi-InitialQuotePunctuation Double High-Reversed-9 Quotation Mark
‹ U+2039 Pi-InitialQuotePunctuation Single Left-Pointing Angle Quotation Mark
› U+203A Pf-FinalQuotePunctuation Single Right-Pointing Angle Quotation Mark
❮ U+276E Ps-OpenPunctuation Heavy Left-Pointing Angle Quotation Mark Ornament
❯ U+276F Pe-ClosePunctuation Heavy Right-Pointing Angle Quotation Mark Ornament
⹂ U+2E42 Ps-OpenPunctuation Undefined
〝 U+301D Ps-OpenPunctuation Reversed Double Prime Quotation Mark
〞 U+301E Pe-ClosePunctuation Double Prime Quotation Mark
〟 U+301F Pe-ClosePunctuation Low Double Prime Quotation Mark
" U+FF02 Po-OtherPunctuation Fullwidth Quotation Mark
' U+FF07 Po-OtherPunctuation Fullwidth Apostrophe
是什麼奇怪的撇號的ASCII碼?順便說一句,反向角色看起來有點像一個奇怪的撇號,但不像你告訴我們的那個人。反引號字符用作PS字符串中的轉義符。 –
在批處理文件中是否有'echo'打印特殊撇號(可以肯定,它不是編碼問題)?此外,您需要在單引號字符串內轉義該特殊撇號,因爲對於PowerShell,特殊撇號是有效的單引號字符:'-replace'''','''。 – PetSerAl
你也許可以做一個正則表達式。如果我複製並粘貼怪異的撇號到regex101它確實認識到它是不同的。即使你不知道它是什麼,那至少可以讓你替換它。 – Nick