Get specific subdomain from URL in foo.bar.car.com

后端 未结 7 1774
清酒与你
清酒与你 2020-11-30 10:19

Given a URL as follows:

foo.bar.car.com.au

I need to extract foo.bar.

I came across the following code :

pr         


        
7条回答
  •  没有蜡笔的小新
    2020-11-30 10:35

    I would recommend using Regular Expression. The following code snippet should extract what you are looking for...

    string input = "foo.bar.car.com.au";
    var match = Regex.Match(input, @"^\w*\.\w*\.\w*");
    var output = match.Value;
    

提交回复
热议问题