Intercepts the specified string in a string, intercepts the domain name, and attempts to intercept the domain name of the different URLs?

Source: Internet
Author: User

/*** Intercept the specified string in a string, intercept the domain name, try to intercept the domain name of different URLs? * For example www.163.com,www.sohu.com.cn * string interception requires the location of the substring () * index, where you need to find the first " ." As the starting index for each domain name, then find the next ("." +1) as the end position * The first point is easy to find, IndexOf, 2nd, with indexof (".", before "." +1) Find*/ Public classStringDemo6 { Public Static voidMain (string[] args) {String http= "Www.163.com"; String HTTP2= "www.sohu.com.cn"; intIndex1 = Http2.indexof (".")); intIndex2 = Http2.indexof (".", Index1+1); String DomainName= HTTP2. substring (index1+1, INDEX2);    System.out.println (DomainName); }}
View Code

/**
* In a string to intercept the specified string, domain name interception, try to intercept different URLs of the domain name?
* Like www.163.com,www.sohu.com.cn
* String interception is required with substring ()
* The location of the index, you need to find the first "." As the starting index for each domain name, then find the next ("." +1) as the end position
* First point is easy to find, IndexOf, 2nd, with indexof (".", before "." +1) find
*/

Intercepts the specified string in a string, intercepts the domain name, and attempts to intercept the domain name of the different URLs?

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.