简体   繁体   English

如何搜索子字符串

[英]How to search for a substring

I retrieve xml with several nodes this type 我用这种类型的几个节点检索xml

<pickUpPoint puCost="0" code4county="UK*LINCS" puKey="C021P008">
    Louth
</pickUpPoint>

and I've got a string formed from the puKey and the actual value of the node (ie C021P008Louth). 我从puKey和节点的实际值(即C021P008Louth)组成了一个字符串。 What I'm trying to achieve is to search in the whole document for the actual node, but I'm not able for the moment to do something like this 我想要实现的是在整个文档中搜索实际节点,但是暂时无法执行类似操作

xDataForLINQ.Descendants("pickUpPoint")
            .Where(pp =>(tourPickUp.Contains(pp.Attribute("puKey").Value)) = true)
            .FirstOrDefault();

and then check if the value matches the second part of my string (using contains as well). 然后检查该值是否与我字符串的第二部分匹配(以及使用contains)。

Perhaps using 也许使用

xDataForLINQ.Descendants("pickUpPoint")
            .FirstOrDefault(p => (string) p.Attribute("puKey") + p.Value == tourPickUp)

is clearer and more precise. 更清晰,更精确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM