[.Net] with regular dismantling Chinese address

Abstract: [. Net] with regular dismantling Chinese address


Preface:

Because of their work to the customer-entered the address for dismantling classification, read the previous write code using indexOf + Substring to disassemble a whole string of address.

In view of this Hyperactivity I feel that way though a solution, but not a good solution. And for the address of China Taiwan, it may not be able to fully meet the rules index when substring.

So I would like to make regular use code clean and simple, still learning to use, the wrong audience for inclusion.

demand:

To have encountered a partial or complete dismantling address to the classification breakdown.

practice:

1. ADDRESS build a class constructor passing the original address.

2. The relevant attributes: City to cities and counties, Region urban township, Village for the village, Neighbor to neighbor, Road to Road, Section for the segment, Lane to Lane, Alley to get, No is the number, Seq is a serial number, Floor to floor, other other.


public class ADDRESS
    {
        public ADDRESS(string address)
        {
            this.OrginalAddress = address;
            this.ParseByRegex(address);
        }

        public static string GetDTName = "SELECT";

        /// 

        /// 县市
        /// 

        public string City { get; set; }

        /// 

        /// 乡镇市区
        /// 

        public string Region { get; set; }

        /// 

        /// 村里
        /// 

        public string Village { get; set; }

        /// 

        /// 邻
        /// 

        public string Neighbor { get; set; }

        /// 

        /// 路
        /// 

        public string Road { get; set; }
        
        /// 

        /// 段
        /// 

        public string Section { get; set; }

        /// 

        /// 巷
        /// 

        public string Lane { get; set; }
        
        /// 

        /// 弄
        /// 

        public string Alley { get; set; }
        
        /// 

        /// 号
        /// 

        public string No { get; set; }
        
        /// 

        /// 序号
        /// 

        public string Seq { get; set; }
        
        /// 

        /// 楼
        /// 

        public string Floor { get; set; }

        public string Others { get; set; }

        /// 

        /// 是否符合pattern规范
        /// 

        public bool IsParseSuccessed { get; set; }

        /// 

        /// 原始传入的地址
        /// 

        public string OrginalAddress { get; private set; }

        private void ParseByRegex(string address)
        {
            var pattern = @"(?D+?[县市])(?D+?(市区|镇区|镇市|[乡镇市区]))?(?D+?[村里])?(?d+[邻])?(?D+?(村路|[路街道段]))?(?
D?段)?(?d+巷)?(?d+弄)?(?d+号?)?(?-d+?(号))?(?d+楼)?(?.+)?";
            
            Match match = Regex.Match(address, pattern);
            
            if (match.Success)
            {
                this.IsParseSuccessed = true;
                this.City = match.Groups["city"].ToString();
                this.Region = match.Groups["region"].ToString();
                this.Village = match.Groups["village"].ToString();
                this.Neighbor = match.Groups["neighbor"].ToString();
                this.Road = match.Groups["road"].ToString();
                this.Section = match.Groups["section"].ToString();
                this.Lane = match.Groups["lane"].ToString();
                this.Alley = match.Groups["alley"].ToString();
                this.No = match.Groups["no"].ToString();
                this.Seq = match.Groups["seq"].ToString();                
                this.Floor = match.Groups["floor"].ToString();
                this.Others = match.Groups["others"].ToString();
            }
            
        }
}

to sum up:

Due to the classification dismantling fine and she did not take into account the road name in there is no way (Penghu County Makung Li lock port pipe lock port) segment generated an error, it took some time to study how to disassemble.

Therefore, in addition to some of the more specific address as the Diaoyutai Islands Spratly Islands and other South China Sea, most of the other can be parsed.

Regular online web and attach the following address:

http://www.rubular.com/

Chinese Taipei Xinyi District Shifu No. 1
Chinese Taipei Da-an District Chung Hsiao East Road, Sec 101, Lane 45
, Lane 39, Xinyi District, Taipei, China Wu Street 220 Lane 11
No. 66-214 Taipei triple Road House
Chinese Taipei's Nankang District 1 synthesis in the North slope neighborhood in Lane 30 19-233 floor of the
Taipei Bade Road, Sec Alley 6, Lane 145, 5th floor, No. 12-2
, Miaoli County, Miaoli City Jiasheng where 25 neighbors Highway 584
Nantou County Datong village Dingyuan New village Road, Renai Township 18-1
Lianjiang nangan Jieshou village 3 o No. 48-2
Penghu Magong Harbor lock in the lock of the Hong Kong section number 1439
250 Taichung Shun Road

Above address any similarity is a coincidence deposit

This article reference URL: http: //www.dotblogs.com.tw/hatelove/archive/2012/06/05/parse-taiwan-address-with-regex.aspx


Original: Large column  [.Net] with regular dismantling Chinese address


Guess you like

Origin www.cnblogs.com/petewell/p/11518127.html