日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

截取Url域名

發布時間:2025/4/16 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 截取Url域名 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://focus.it168.com/focus/201006/mobile/index.html

這是一個常見的Url,如果我們要取得地址中的域名,也就是:

http://focus.it168.com

.net(C#方法實現)

web版本:

?   string str = "http://focus.it168.com/focus/201006/mobile/index.html";
??????? int len1 = str.IndexOf(':')+3;
??????? int len = str.IndexOf('/', len1 , str.Length - len1 );
??????? Response.Write(str.Substring(0,len));

winform版本:

??  string str = "http://focus.it168.com/focus/201006/mobile/index.html";
??????? int len1 = str.IndexOf(':')+3;
??????? int len = str.IndexOf('/', len1 , str.Length - len1 );
??????? Console.WriteLine(str.Substring(0,len));
??  Console.Read();

?

輸出結果:http://focus.it168.com/

其他地址也一樣,大家可以把url當參數傳進來

例如:

?public static void Main()
?{
??string str="http://bj.house.163.com/10/0609/09/68NO989500073SD3.html";
??RL(str);
?}

?private static void RL(string str)
?{
??  int len1 = str.IndexOf(':')+3;
??????? int len = str.IndexOf('/', len1 , str.Length - len1 );
??????? Console.WriteLine(str.Substring(0,len));
??  Console.Read();
?}

?

也就是說,把你要截取的url傳給RL方法,就會返回給你域名

結果:http://bj.house.163.com

?

轉載于:https://www.cnblogs.com/A-I/archive/2010/06/09/1754496.html

總結

以上是生活随笔為你收集整理的截取Url域名的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。