これは私の配列です:
eth1
eth12
eth5
eth11
文字列に 1 ~ 9 の数値が含まれている場合、前に 0 を追加して、次のような配列を取得します。
eth01
eth12
eth05
eth11
どうすればこれを達成できますか? このような文字列を変更する方法がわかりません:/
ありがとう
これは私の配列です:
eth1
eth12
eth5
eth11
文字列に 1 ~ 9 の数値が含まれている場合、前に 0 を追加して、次のような配列を取得します。
eth01
eth12
eth05
eth11
どうすればこれを達成できますか? このような文字列を変更する方法がわかりません:/
ありがとう
このような:
$if = 'eth1', 'eth12', 'eth5', 'eth11'
$if -replace '(\D+)(\d)$', '${1}0$2'
別のオプション:
$if -replace '(?<=\D)(\d)$', '0$1'
アンスガーよりも曲がりくねった方法です:)
$a=@("eth1","eth12","eth5")
$a|%{
$slice=$_.split("h");
if([int]$slice[1] -le 9){
$slice[1]="0"+$slice[1]
}
join-string -strings $slice -separator("h")
}