「PowerShell」TrimStartメソッドで文字列先頭の空白を取り除く
書式
文字列.TrimStart()
TrimStartメソッドを利用して、文字列の先頭の空白を取り除きます。
使用例
# 全角空白あり
$SS = " test abc "
Write-Host($SS.Length)
Write-Host($SS.TrimStart())
Write-Host($SS.TrimStart().Length)
# 半角空白あり
$tt = " test abc "
Write-Host($tt.Length)
Write-Host($tt.TrimStart())
Write-Host($tt.TrimStart().Length)
# 全角空白あり
$SS = " test abc "
Write-Host($SS.Length)
Write-Host($SS.TrimStart())
Write-Host($SS.TrimStart().Length)
# 半角空白あり
$tt = " test abc "
Write-Host($tt.Length)
Write-Host($tt.TrimStart())
Write-Host($tt.TrimStart().Length)
# 全角空白あり $SS = " test abc " Write-Host($SS.Length) Write-Host($SS.TrimStart()) Write-Host($SS.TrimStart().Length) # 半角空白あり $tt = " test abc " Write-Host($tt.Length) Write-Host($tt.TrimStart()) Write-Host($tt.TrimStart().Length)
実行結果
> .\test.ps1
10
test abc
9
11
test abc
10
> .\test.ps1
10
test abc
9
11
test abc
10
> .\test.ps1 10 test abc 9 11 test abc 10