我正在尝试创建一个接受字符串作为参数的函数,并返回<>
之间的字符串列表例如说一个包含以下值的字符串:
UIEdgeInsets(top: composeMessageView.frame.height - 4, left: 0, bottom: 4, right: 0)
我想将每个内容存储在列表中,如下所示:
string s = "<FirstName> John </FirstName> <LastName> Snow </LastName>";
结果将是:
List<string> container = new List<string>();
container = getTypes(s);
foreach(string s in container){
Console.WriteLine(s);
}
我该怎么做?
答案 0 :(得分:1)
string s = "<FirstName> John </FirstName> <LastName> Snow </LastName>";
var x = System.Xml.Linq.XElement.Parse("<x>" + s + "</x>"); // needs single root element
foreach(var el in x.Elements())
Debug.Print(el.Name.LocalName + " : " + el.Value);