【发布时间】:2022-11-17 02:44:00
【问题描述】:
我的问题是:
function GetStringBetweenTwoStrings($firstString, $secondString, $importPath){
#Get content from file
$file = Get-Content $importPath
#Regex pattern to compare two strings
$pattern = "$firstString(.*?)$secondString"
#Perform the opperation
$result = [regex]::Match($file,$pattern).Groups[1].Value
#Return result
return $result
}
GetStringBetweenTwoStrings -firstString "Lorem" -secondString "is" -importPath "C:\Temp\test.txt"
这对只有一个 -firstString 和 -secondString 来说很好,但是如何使用此函数按时间顺序在编号的 TXT 中写入多个相同的字符串?
txt - file(with more sections of text):
Lorem
....
is
--> write to 001.txt
Lorem
....
is
--> write to 002.txt
and so forth....
并且节的结构得以保留,不在一行中。
我希望有人能告诉我。谢谢。
【问题讨论】:
标签: string powershell extract