【发布时间】:2016-11-10 23:39:04
【问题描述】:
问题:
我的脚本的目的是从两个文本文件中过滤掉姓名和电话号码,并将它们添加到一个哈希表中,其中名称是键,电话号码是值。
我面临的问题是
$name = $_.Current 正在返回 $null,因此我的哈希没有被填充。
谁能告诉我是什么问题?
File1.txt 的内容:
萝莉
东二街 234 号
罗利数控 12345
9199617621
lori@hotmail.com
==================
File2.txt 内容:
罗伯特
第十大道 2531 号
西雅图 WA 93413
2068869421
robert@hotmail.com
示例代码:
$hash = @{}
Switch -regex (Get-content -Path C:\Users\svats\Desktop\Fil*.txt)
{
'^[a-z]+$' { $name = $_.current}
'^\d{10}' {
$phone = $_.current
$hash.Add($name,$phone)
$name=$phone=$null
}
default
{
write-host "Nothing matched"
}
}
$hash
【问题讨论】: