本文介绍了正则表达式,我可以将它用于此任务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我正在开发一个需要在XML文件中查找信息的程序,格式如下:http://www.hrdsoftwarellc.com/hrdxmlcountries/LogbookCountryDataEx。 xml



标签PrefixList是我打算使用的字段,我的问题是找到一个很好的方法来做到这一点。



我的程序需要找出无线电业余呼号的位置。



我呼号是位于丹麦的PrefixList标签是:

PrefixList =5 [PQ]。* | O [UVZ ]。*



呼号示例:OZ1BV,5Q5P,5P9XYZ,UO9S,OV5RT等等。


如果呼号位于德国,则PrefixList标签为:

PrefixList =D [AR]。*



电话签名示例:DA7T,DB4TY,DC2EW,DR8RE等等。


加拿大:

PrefixList =C [FGJK]。* | C [HY] [12]。* | C [IZ] [012] * | V [ABCEGX] * | V [DO] [12] * | V [FY] [012]。* | X [JN] [12]。* | X [KO] [012]。* | X [LM]。*



使用正则表达式可以解决这个问题吗?



祝你好运,Brian

Hi
I am working on a program that needs to lookup information in a XML file, formatted like this: http://www.hrdsoftwarellc.com/hrdxmlcountries/LogbookCountryDataEx.xml

The tag "PrefixList" is the field I intend to use and my problem is to find a nice way to do it.

My program need to find out from which country a radio amateur call sign is located.

I the call sign is located in Denmark the PrefixList tag is:
PrefixList="5[PQ].*|O[UVZ].*"

Call sign examples: OZ1BV, 5Q5P, 5P9XYZ, UO9S, OV5RT, ect.

If the call sign is located in Germany the PrefixList tag is:
PrefixList="D[A-R].*"

Call sign examples: DA7T, DB4TY, DC2EW, DR8RE, ect.

Canada:
PrefixList="C[FGJK].*|C[HY][12].*|C[IZ][012].*|V[ABCEGX].*|V[DO][12].*|V[FY][012].*|X[JN][12].*|X[KO][012].*|X[LM].*"

Can this problem solved using a regular expression?

Best regards, Brian

推荐答案

var xml = XDocument.Load(@"http://www.hrdsoftwarellc.com/hrdxmlcountries/LogbookCountryDataEx.xml");

var cs = from c in xml.Root.Elements("Countries001").Elements("item")
         select new
         {
         Latitude=c.Attribute("Latitude").Value,
         Longitude=c.Attribute("Longitude").Value,
         re = new Regex(c.Attribute("PrefixList").Value, RegexOptions.IgnoreCase)
         };

var us = from u in xml.Root.Elements("UniqueCalls001").Elements("item")
         let c = cs.FirstOrDefault( x=> x.re.IsMatch(u.Attribute("Callsign").Value))
         select new
         {
         CallSign = u.Attribute("Callsign").Value,
         Latitude = c.Latitude,
         Longitude = c.Longitude
         };

us.Dump();


这篇关于正则表达式,我可以将它用于此任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 07:18