我正试图从应用程序的输出中获取路径。 这是输出样本:
如何解析输出只是" C:\ MyDir \ Smith_Nathalie_20170428_140834479"并重用它来告诉storescu(发送dicom文件)要查看的路径。
ex:Storesu 106 + sd" C:\ MyDir \ Smith_Nathalie_20170428_140834479"
任何帮助都会很棒。
答案 0 :(得分:1)
查看System.IO.Path.GetDirectoryName()
https://msdn.microsoft.com/en-us/library/system.io.path.getdirectoryname(v=vs.110).aspx
编辑(再次)
您可以使用正则表达式解析字符串中的文件名。对于您显示的字符串,我建议让Regex查找有关创建新子目录的消息。它看起来像这样
string directoryName = string.Empty;
string inputtext = @"creating new subdirectory for study: C:\MyDir\Smith_Nathalie_20170428_140834479 I: storing DICOM file: C:\MyDir\Smith_Nathalie_20170428_140834479\DXm.1.2.840.113681.2206606139.739.3355346425.685.1 I: Received Store Request: MsgID 2, (DXm) RECV: ..................................................................................... I: storing DICOM file: C:\MyDir\Smith_Nathalie_20170428_140834479\DXm.1.2.840.113681.2206606139.739.3355346425.687.1 I: Received Store Request: MsgID 3, (DXm)";
System.Text.RegularExpressions.MatchCollection matchCol = System.Text.RegularExpressions.Regex.Matches(inputtext, @"(?<=creating new subdirectory for study: )[^\s]+(?=\s)");
if (matchCol.Count > 0)
directoryName = matchCol[0].Value;