Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static String getBasUrl(String url) { String head = ""; int index = url.indexOf("://"); if (index != -1) { head = url.substring(0, index + 3); url = url.substring(index + 3); } index = url.indexOf("/"); if (index != -1) { url = url.substring(0, index + 1); } return head + url; } }