zoukankan      html  css  js  c++  java
  • C# 关于URL地址操作

    // 获取域名(不包括二级域名)
        public string GetUrlDomainName(string strHtmlPagePath)
        {
            
    string p = @"http://[^\.]*\.(?<domain>[^/]*)";
            Regex reg 
    = new Regex(p, RegexOptions.IgnoreCase);
            Match m 
    = reg.Match(strHtmlPagePath);
            
    return m.Groups["domain"].Value;
        }
    // 截取域名(包括二级域名)
    Uri uriTmp = new Uri(@"http://fff.sohu.com/newsecond/searchmore/bs-CS__address_sdf--1_ff=ffffssssss.htm");
    Response.Write(uriTmp.Host.ToString());


    其他操作:
        public string[] GetUrlFolerName(string strHtmlPagePath)
        {
            
    //抓取网址字符串中的文件目录

            
    int at = 0;
            
    int start = 0;
            
    int notei = 0;
            
    int endi = 0;
            
    int[] myIntArray = new int[10];
            
    string[] ArrayFolderName = null;
            
    string NewFolderName;
            
    while ((start < strHtmlPagePath.Length) && (at > -1))
            {
                at 
    = strHtmlPagePath.IndexOf('/', start);
                
    if (at == -1break;
                myIntArray[notei] 
    = at;
                start 
    = at + 1;
                notei 
    = notei + 1;
                endi 
    = at;
            }
            ArrayFolderName 
    = new string[notei - 1];
            
    for (int i = 0; i < notei; i++)
            {
                
    if (myIntArray[i] > 0)
                {
                    
    if (myIntArray[i + 1> 0)
                    {
                        NewFolderName 
    = strHtmlPagePath.Substring(myIntArray[i] + 1, myIntArray[i + 1- myIntArray[i] - 1);
                        ArrayFolderName.SetValue(NewFolderName, i);
                    }

                }
            }
            
    return ArrayFolderName;
        }

        
    public string GetUrlFileName(string strHtmlPagePath)
        {
            
    //抓取网址字符串中的文件名称
            int at = 0;
            
    int start = 0;
            
    int notei = 0;
            
    int endi = 0;
            
    int[] myIntArray = new int[10];
            
    string NewFileName = "";
            
    while ((start < strHtmlPagePath.Length) && (at > -1))
            {
                at 
    = strHtmlPagePath.IndexOf('/', start);
                
    if (at == -1break;
                myIntArray[notei] 
    = at;
                start 
    = at + 1;
                notei 
    = notei + 1;
                endi 
    = at;
            }

            
    for (int i = 0; i < notei; i++)
            {
                
    if (myIntArray[i] > 0)
                {
                    
    if (myIntArray[i + 1== 0)
                    {
                        NewFileName 
    = strHtmlPagePath.Substring(myIntArray[i] + 1, strHtmlPagePath.Length - myIntArray[i] - 1);

                    }
                }
            }
            
    return NewFileName.ToLower();

        }
  • 相关阅读:
    解决mac中wxpython对64位的支持
    python翻译词典实例
    php断点续传
    ubuntu配置telnet服务
    *p++,*++p,*(p++),*(++p)
    在main函数前后执行的函数之 C语言
    串行通讯协议--起止式异步通讯协议(UART)
    TTL电平, RS232电平以及CMOS电平的区别
    C 语言的关键字static 和C++ 的关键字static 有什么区别
    C语言各种数据类型取值范围
  • 原文地址:https://www.cnblogs.com/wangpei/p/1371149.html
Copyright © 2011-2022 走看看