Powershell 之后移除任何东西。(点)。包括dot
我如何(通过Powershell)删除topleveldomain(TLD),以便获得以下结果:Powershell 之后移除任何东西。(点)。包括dot,powershell,split,Powershell,Split,我如何(通过Powershell)删除topleveldomain(TLD),以便获得以下结果: subdomain1.google.nl subdomain1.subdomain2.google.com subdomain1.facebook.com subdomain1.subdomain2.facebook.com 您可以尝试正则表达式模式,也可以尝试以下方法: subdomain1.google subdomain1.subdomain2.google subdomain1.faceb
subdomain1.google.nl
subdomain1.subdomain2.google.com
subdomain1.facebook.com
subdomain1.subdomain2.facebook.com
您可以尝试正则表达式模式,也可以尝试以下方法:
subdomain1.google
subdomain1.subdomain2.google
subdomain1.facebook
subdomain1.subdomain2.facebook
输出:
$string = 'subdomain1.google.nl'
[io.path]::GetFileNameWithoutExtension($string)
事实上!我很好奇什么是最好的绩效评估方法,猜猜看:
subdomain1.google
平均值
$results = @()
for ($i=1;$i -le 1000;$i++){
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name 'Execution #' -Value $([int]$i)
$obj | Add-Member -MemberType NoteProperty -Name 'IOPath_Ticks' -Value $(Measure-Command -Expression {[System.IO.Path]::GetFileNameWithoutExtension('subdomain1.google.nl')} | Select -ExpandProperty Ticks)
$obj | Add-Member -MemberType NoteProperty -Name 'Regex_Ticks' -Value $( Measure-Command -Expression {'subdomain1.google.nl' -replace '\.[^.]*?$'} | Select -ExpandProperty Ticks)
$results += $obj
}
总数
因此,正如您所看到的,当您需要处理大量记录时,与正则表达式相比,.NET类的使用效果最好
$results | Measure-Object -Property IOPath_Ticks -Sum
Count : 1000
Average :
Sum : 129978
Maximum :
Minimum :
Property : IOPath_Ticks
$results | Measure-Object -Property Regex_Ticks -Sum
Count : 1000
Average :
Sum : 364560
Maximum :
Minimum :
Property : Regex_Ticks
'subdomain1.subdomain2.facebook.com'-replace'\.[^.]*?$'
创造性地滥用静态方法FTW.)@AnsgarWiechers,真的!我有一些测试,看看数字:-)
$results | Measure-Object -Property IOPath_Ticks -Sum
Count : 1000
Average :
Sum : 129978
Maximum :
Minimum :
Property : IOPath_Ticks
$results | Measure-Object -Property Regex_Ticks -Sum
Count : 1000
Average :
Sum : 364560
Maximum :
Minimum :
Property : Regex_Ticks
$val="subdomain1.google.nl"
$val.substring(0,$val.LastIndexOfAny("."))
$val="subdomain1.subdomain2.google.com"
$val.substring(0,$val.LastIndexOfAny("."))
$val="subdomain1.facebook.com"
$val.substring(0,$val.LastIndexOfAny("."))
$val="subdomain1.subdomain2.facebook.com"
$val.substring(0,$val.LastIndexOfAny("."))