
基本上,我想搜尋一個字串並以 CSV 格式傳回任何完整或部分匹配項。
假設我有一個$Shoes
看起來像這樣的物件:
"Brand","Style","Color","Price"
"Reebok","Basketball","Red/Black","$50"
"Vans","Slip-On","White/Black","$60"
"Vans","Old Skool","Red/White","$60"
"Nike","Sneakers","Red","$50"
"Adidas","Sneakers","Blue","$55"
為了使其更具可讀性,格式化為表格如下:
Brand Style Color Price
----- ----- ----- -----
Reebok Basketball Red/Black $50
Vans Slip-On White/Black $60
Vans Old Skool Red/White $60
Nike Sneakers Red $50
Adidas Sneakers Blue $55
鍵入$Shoes -like '*Red*'
返回:
@{Brand=Reebok; Style=Basketball; Color=Red/Black; Price=$50}
@{Brand=Vans; Style=Old Skool; Color=Red/White; Price=$60}
@{Brand=Nike; Style=Sneakers; Color=Red; Price=$50}
但我正在尋找的輸出是:
Brand Style Color Price
----- ----- ----- -----
Reebok Basketball Red/Black $50
Vans Old Skool Red/White $60
Nike Sneakers Red $50
我在這裡做錯了什麼?
答案1
我想當我嘗試時我格式 -match 不正確,結果是簡單的解決方案...
這簡直就是$Shoes -match 'Red'