1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

文字列を辞書型に変換(EdgeのF12のリクエストヘッダー向け)

Posted at

ConvertFrom-StringData

ConvertFrom-StringData $textで「name=value」の形式で書かれた文字列を辞書型に変換できます。

Edgeで表示されるリクエスト/レスポンスヘッダへの応用

正規表現で「name=value」になるように変換します。

$text -replace "(\r\n|^)(.*):", "`r`n$2="

PowerShellだとバッククオートでエスケープしますが、正規表現ではバックスラッシュです。

^は処理単位の先頭を表すらしいですが、今回のケースだと行頭を意味しないので\r\nで行頭を示しました。

また、素で書くと「foo-bar」のようなハイフンを含むキーは「"foo-bar"」としなければなりませんが、ConvertFrom-StringDataで処理する場合はいらないようです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?