Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Старожил


Сообщения: 250
Благодарности: 51

Профиль | Отправить PM | Цитировать


@DJ Mogarych а не проще разве отрезать бом ?


Код: Выделить весь код
. .\strip_bom.ps1 test1.txt
Код: Выделить весь код
 Directory: C:\Users\Serguei


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        6/10/2021  12:01 AM             10 test1.txt.new
-a----        6/10/2021  12:00 AM             13 test1.txt

Код: Выделить весь код
od -x test1.txt ; od -x test1.txt.new
0000000 bbef d1bf d082 d0b5 d1ba d181 0082
0000015
0000000 82d1 b5d0 bad0 81d1 82d1
0000012
UTF-8
The UTF-8 representation of the BOM is the (hexadecimal) byte sequence 0xEF,0xBB,0xBF.

сам скрипт:

Код: Выделить весь код
param(
  [String]$source,
  [String]$dest = "${source}.new"
)
# https://stackoverflow.com/questions/288111/remove-byte-order-mark-from-a-file-readallbytes-byte

$text = [System.IO.File]::ReadAllText($source)
$writer = new-object System.IO.StreamWriter($dest, $false, (new-object System.Text.UTF8Encoding($false)))
$writer.Write($text)
$writer.Close()
Это сообщение посчитали полезным следующие участники:

Отправлено: 07:15, 10-06-2021 | #17