选择字符串数组特定部位

编程入门 行业动态 更新时间:2024-10-26 22:19:44
本文介绍了选择字符串数组特定部位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

选择字符串数组特定部位

本文发布于:2023-10-28 05:32:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535675.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字符串   部位

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!