我正在为 iTunes XML 文件编写解析器,我正在尝试解析文件位置以允许应用程序从 de 文件夹中恢复 folder.jpg。
我正在以这种格式从 itunes.xml 的位置创建一个 URI:
\\localhost\C:\MP3 Collection\Álbuns\# - E\A\a-ha\[1985] Hunting High And Low\01. Take On Me.mp3
我需要提取 01。将 On Me.mp3
子字符串替换为 folder.jpg
。
请记住,这个字符串在每个文件中都是不同的。
最佳答案
您可以使用 Path.GetDirectoryName Method和 Path.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"
关于c# - 在 C# 中对 URI 的字符串操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9254680/