A simple small program for splitting URLs

Source: Internet
Author: User
Package Org. wiksys; public class spliturl {/*** @ author wiksys * @ Param ARGs */public static void main (string [] ARGs) {read ("http://www.baidu.com/index.jsp ");} public static void read (string URL) {// string url = "http://www.baidu.com: 8080/index. JSP "; // string url2 =" ftp://baidu.com/pub/index.jsp "; int firsplit = URL. indexof ("//"); string proto = URL. substring (0, firsplit + 2); int websplit = URL. indexof ("/", firsplit + 2); int portindex = URL. indexof (":", firsplit); string weburl = URL. substring (firsplit + 2, websplit); string port = ""; if (portindex> = 0) {weburl = weburl. substring (0, weburl. indexof (":"); Port = URL. substring (portindex + 1, websplit); system. out. println ("port:" + port);} string context = URL. substring (websplit); system. out. println ("Protocol:" + PROTO); system. out. println ("url:" + weburl); system. out. println ("content:" + context );}}

The code is very simple, so you don't need to explain it too much. You can simply split the block into four parts based on the URL: If there is no port, it is blocked.

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.