Powershell: Find/Replace pattern of ASCII control characters

后端 未结 3 1083
长发绾君心
长发绾君心 2021-01-12 15:52

I\'m trying to write a script to search the contents of a file, and when it comes across a grouping of ASCII control characters, to insert a CR/LF.

The pattern of ch

3条回答
  •  长情又很酷
    2021-01-12 16:12

    Michael Sorens' helpful answer explains the problem with your approach well and offers a working solution.

    To offer a simpler alternative:

    $CR = ([char[]] (3, 0, 2, 3, 1)) -join ''
    
    • 3, 0, 2, 3, 1 creates an array of integers with the Unicode code points of the characters to create.

    • Cast [char[]] converts the code points to actual characters ([char]).

    • -join '' joins the array of characters (with no separator) to for a single string.

提交回复
热议问题