我有2個參數,第一個是文本文件,第二個是csv文件。使用csv數據替換文本
的第一個文件的樣子:
(name) from (address) is (age) years old.
第二個文件的樣子:
Name,Address,Age
James,London,34
Alex,New York,25
我要取代這個:(名)到詹姆斯(地址)(倫敦)和(歲)到34等等
我想這個輸出:James from London is 34 years old.
等等
所以浩我可以將csv文件的數據存儲在多維數組中嗎? 喜歡這個$數據[行號] [列號] 例如,$數據[1] [0]應該是:亞歷
我的代碼:
$parameter = $args[0]
$data = $args[1]
for($i = 1; $i -lt $data.lenght/3; $i++)
{
$parameter.replace('(name)', '???') | Set-Content $parameter
$parameter.replace('(address)', '???') | Set-Content $parameter
$parameter.replace('(age)', '???') | Set-Content $parameter
#I want to output $parameter
}
如果您使用'$ data = Import-CSV「pathtocsvfile.csv」',您將在'$ data [1] .Name'中使用'Alex',或在$ data [0]中使用'London'。地址「,會爲你工作嗎? – sodawillow
如何輸出$參數? 寫主機不起作用 –
我認爲你必須使用'return' – user4317867