选择字符串数组特定部位 [英] Select specific parts in string array

查看:164
本文介绍了选择字符串数组特定部位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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>
&lt;Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:s="clr-namespace:System; ...   
TextBox VerticalAlignment="Center"&gt;my Data&lt;/TextBox&gt;&lt;/Grid&gt;
</Content>

现在我想只提取了我的数据这个阵列的一部分。根据我的previous <一个href=\"http://stackoverflow.com/questions/24865632/omit-unnecessary-parts-in-string-array\">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.

这篇关于选择字符串数组特定部位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆