2012-02-13 43 views
3

我正在爲iTunes XML文件編寫解析器,我試圖解析文件位置以允許應用程序從de文件夾中恢復folder.jpg。字符串操作到C#中的URI

我從itunes.xml的位置,以這種格式創建一個URI:

\\localhost\C:\MP3 Collection\Álbuns\# - E\A\a-ha\[1985] Hunting High And Low\01. Take On Me.mp3 

我需要提取01. Take On Me.mp3子與folder.jpg更換。

請記住,該字符串在每個文件中都不相同。

回答

4

您可以使用Path.GetDirectoryName MethodPath.Combine Method

var s = @"\\localhost\C:\MP3 Collection\Álbuns\# - E\A\a-ha\[1985] Hunting High And Low\01. Take On Me.mp3"; 

var result = Path.Combine(Path.GetDirectoryName(s), "folder.jpg"); 
// result == @"\\localhost\C:\MP3 Collection\Álbuns\# - E\A\a-ha\[1985] Hunting High And Low\folder.jpg"