LoginSignup
0
0

More than 1 year has passed since last update.

PowerShellフォーマット演算子について

Last updated at Posted at 2022-08-16

前回PowerShellにて16進数ダンプ。の記事で触れたが内容がずれるのでこちらに記事とした。

フォーマット演算子について
「-f」はフォーマット演算子

フォーマット演算子.ps1
#文字列
$a="hello"
Write-Output("'{0,8}'"-f$a)#文字列の前にスペースが3つある
Write-Host("'{0,-8}'"-f$a)#文字列の後にスペースが3つある
Write-Host""

#数値
$a=254
Write-Host("{0}"-f$a)#数値の後にスペースはない
Write-Host("{0,8}"-f$a)#数値の前にスペースが5つある
Write-Host("{0,-8}"-f$a)#数値の後にスペースが5つある
Write-Host("{0:00000000}"-f$a)#数値のまえに「0」が5つある
Write-Host("{0:d8}"-f$a)#数値のまえに「0」が5つある

#基数変換

$a=0xEA
Write-Output("{0:x4}"-f$a)#「x」小文字で表現、「00ea」となる

$a=0xea
Write-Output("{0:X4}"-f$a)#「X」大文字で表現、「00EA」となる


【参考文献】

0
0
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
0
0