我有一个文件中包含的内容:捕获某个子字符串的最佳方法?
garbage
garbage
printfile ps = "Elopak Zufriedenheit After Sales.ps";
garbage
garbage
我想捕捉""
(双引号)之间的部分 - 但该部分的值更改不断。我写了一个正则表达式找到printfile ps
- 但是从那里出发最好的方法是什么?
新代码:
Dim PFileRegex As New Regex("printfile ps *\t*= *\t*""[\w\s]*.ps\s*""")
Dim PFilematch As Match = PFileRegex.Match(parttext)
If PFilematch.Success = True Then
Dim Quote As Char = """"c
Dim FirstQuote = PFilematch.Value.IndexOf(Quote)
Dim LastQuote = PFilematch.Value.LastIndexOf(Quote)
Dim PSFile = PFilematch.Value.Substring(FirstQuote + 1, (LastQuote - FirstQuote) - 1)
Debug.Print(PSFile)
Else
'error handlung
End If
ahh谢谢,这真的很整洁! – 2013-03-07 13:38:37