C#解析目录路径的输出

C#解析目录路径的输出,c#,.net,C#,.net,我试图从应用程序的输出中获取路径。 以下是输出示例: 如何解析“C:\MyDir\Smith\u Nathalie\u 20170428\u 140834479”的输出,并重新使用它来告诉storescu(发送dicom文件)要查找的路径 例如:Storesu 106+sd“C:\MyDir\Smith\u Nathalie\u 20170428\u 140834479” 任何帮助都会很好。请查看System.IO.Path.GetDirectoryName() 编辑(再次) 可以使用正则表

我试图从应用程序的输出中获取路径。 以下是输出示例:

如何解析“C:\MyDir\Smith\u Nathalie\u 20170428\u 140834479”的输出,并重新使用它来告诉storescu(发送dicom文件)要查找的路径

例如:Storesu 106+sd“C:\MyDir\Smith\u Nathalie\u 20170428\u 140834479”


任何帮助都会很好。

请查看
System.IO.Path.GetDirectoryName()

编辑(再次)

可以使用正则表达式从字符串中解析文件名。对于显示的字符串,我建议让正则表达式查找关于创建新子目录的消息。看起来是这样的

        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;
string directoryName=string.Empty;
string inputtext=@“为研究创建新子目录:C:\MyDir\Smith_Nathalie_20170428_140834479 I:存储DICOM文件:C:\MyDir\Smith_Nathalie_20170428_140834479\DXm.1.2.840.113681.2206606139.739.3355346425.685.1 I:收到的存储请求:MsgID 2,(DXm)记录:I:存储DICOM文件:C:\MyDir\Smith_Nathalie_20170428_140834479\DXm.1.2.840.113681.2206606139.739.3355346425.687.1 I:收到的存储请求:MsgID 3,(DXm)”;

System.Text.RegularExpressions.MatchCollection matchCol=System.Text.RegularExpressions.Regex.Matches(inputtext,@)(?请澄清您的具体问题或添加其他详细信息以突出显示您需要的内容。由于目前编写的内容,很难准确说出您的问题。有关澄清此问题的帮助,请参阅页面
System.IO.Path.GetDirectoryName(myFullPath)
我包含了输出的一个像素。复制粘贴时输出的格式不正确。希望这能澄清问题。再次使用thx。@ChristopherDoty我已为您最近的编辑更新了我的答案。