在C#中,我得到了来自这样一个XML文件的字符串数组(此XML文件是由一个基于XAML的UI保存):
In C#, I was given a string array from an XML file like this (this xml file is saved by an xaml based UI):
<Content> <Grid xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:s="clr-namespace:System; ... TextBox VerticalAlignment="Center">my Data</TextBox></Grid> </Content>现在我想只提取了我的数据这个阵列的一部分。根据我的previous question,我想这样做是这样的:
Now I want to extract only the "my Data" part of this array. Based on my previous question, I tried to do that in this way:
var pair = keyValue.Split('='); if (pair[0] == "VerticalAlignment") { var parts = pair[1].Split(';').Skip(1).Take(1); string output= string.Join("", parts); }我也试过用不同的字符,如&安培; '分裂等,但它给了我一个空的输出字符串。预期的结果应该是:
I also tried to split with different characters like '&', etc. But it gives me an empty output string. The expected result should be:
output = "my Data";如何做到这一点?先谢谢你。
How to do that? Thank you in advance.
推荐答案好吧,我解决了通过解析XML字符串为的XElement ,然后得到的值的文本框元素。
Ok, I solved it by parsing the xml string as XElement, and then get the value of its TextBox element.
更多推荐
选择字符串数组特定部位
发布评论