我使用字符串来表示图像文件名中的名称/值对。
string pairs = image_attribs(color,purple;size,large).jpg;
我需要解析该字符串以获取分号前后的名称/值对。我可以拆分分号并减去左括号的长度,但我希望相应的函数可以扩展到多对。
我需要想出一个可以返回这些对的多子字符串函数。然后,我将它们设为 KeyValuePairs 列表:
List<KeyValuePair<string, string>> attributes = new List<KeyValuePair<string, string>>();
当前解析仅获取第一对:
string attribs = imagepath.Substring(imagepath.IndexOf("(") +1, imagepath.IndexOf(";" - imagepath.IndexOf("(");
我已经拥有解析逗号分隔对以创建和添加新 KeyValuePair 的功能。