C # URL operations

Source: Internet
Author: User

 

 

// Retrieve domain name (excluding second-level domain names)
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;
}

 

// Domain Name truncation (including second-level domain names)
Uri uritmp =   New Uri ( @" Http://fff.sohu.com/newsecond/searchmore/bs-CS__address_sdf--1_ff=ffffssssss.htm " );
Response. Write (uritmp. Host. tostring ());

Other operations: Public   String [] Geturlfolername ( String Strhtmlpagepath)
{
// Capture the file directory in the URL string

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) && ( >   - 1 ))
{
At = Strhtmlpagepath. indexof ( ' / ' , Start );
If ( =   - 1 ) Break ;
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 );
}

}
}
ReturnArrayfoldername;
}

Public   String Geturlfilename ( String Strhtmlpagepath)
{
// Capture the file name in the URL string
Int At =   0 ;
Int Start =   0 ;
Int Notei =   0 ;
Int Endi =   0 ;
Int [] Myintarray =   New   Int [ 10 ];
String Newfilename =   "" ;
While (Start < Strhtmlpagepath. length) && ( >   - 1 ))
{
At = Strhtmlpagepath. indexof ( ' / ' , Start );
If ( =   - 1 ) Break ;
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 );

}
}
}
ReturnNewfilename. tolower ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.