rsc*_*rin 2 powershell powershell-2.0
我需要读取如下组成的txt文件:
AA=1000,AA=320009#999999
AA=1011,AA=320303#111111
Run Code Online (Sandbox Code Playgroud)
对于每个引线,我需要用"#"分割它以获得第一个转弯
$test[0] = AA=1000,AA=320009 and $test[1]=999999
Run Code Online (Sandbox Code Playgroud)
在第二个回合
$test[0] = AA=1000,AA=320003 $test[1]= 1111111
Run Code Online (Sandbox Code Playgroud)
我有一些问题需要了解如何使用get-content或获取它.
# Basically, Get-Content will return you an array of strings such as below:
# $tests = Get-Content "c:\myfile\path\mytests.txt"
$tests = @(
"AA=1000,AA=320009#999999",
"AA=1011,AA=320303#111111"
)
$tests | %{ $test = $_ -split '#'; Write-Host $test[0]; Write-Host $test[1] }
Run Code Online (Sandbox Code Playgroud)
上面的行相当于:
$tests | foreach {
$test = $_ -split '#'
Write-Host $test[0]
Write-Host $test[1]
}
Run Code Online (Sandbox Code Playgroud)
这意味着对于$ lines的每一行(每行由$ _实现,一个在'#'上进行拆分(它产生一个在Write-Host语句中使用的数组)