【发布时间】:2018-11-27 16:29:57
【问题描述】:
我有一个全名数组,
$doctors = @(
'John Q. Smith',
'Mary X. Jones',
'Thomas L. White',
"Sonia M. O'Toole"
)
我想只从该字段将姓氏传递给变量。或者也许只有firstinitiallastname。这是我目前给我的名字后缀:
try {
# add firstnames to list
$firstnames = New-Object System.Collections.ArrayList
foreach ($doctor in $doctors) {
$docname = ($doctor -split '\s')
$docname = $docname[0]+$docname[-1][0]
$firstnames += $docname
}
同样,我只想查看姓氏。如何为此调整此代码?
【问题讨论】:
-
$lastName = $docName[-1] -
谢谢!我会修补一下,看看有什么用。谢谢你的建议。
标签: string powershell text