2
2

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 1 year has passed since last update.

配列に文字を追加して別の配列に格納する

Posted at

Powershellで配列に文字を追加して別の配列に格納するスクリプトを実装しました。

######### 配列から名前を取得し、文字列を配列に格納する###
######### 新規作成 2023/3/4          ####################
#########################################################


#乱数を格納する変数
$ans = 0
#カウント変数
$cnt = 0
#大食いメッセージ
$msg = "は大食いです"
#データ配列
$data = @("松村沙友理","生田絵梨花","梅澤美波","池田瑛紗","向井葉月")
#結果配列
$result = @();
$result1 = ""

##ランダムの数字を発生するユーザー定義関数
function random(){
    $ans =  Get-Random -Minimum 1 -Maximum 20
    return $ans
}

#5回ループを繰り返し、配列の要素を5つ入れる
while ($cnt -lt 5 ){
    $ans1 = random
    #リターンコードを整数に変換して5で割る
    $ans1 = [int] $ans1 % 5
    # 5で割った余りで判定する
    $result += $data[$ans1] + $msg
    $cnt++
}            

#配列の要素を取り出す
foreach($data in $result){
    Write-Host($data)
}    
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?