Java tutorial
//package com.java2s; public class Main { public static String getHostName(String urlString) { String head = ""; int index = urlString.indexOf("://"); if (index != -1) { head = urlString.substring(0, index + 3); urlString = urlString.substring(index + 3); } index = urlString.indexOf("/"); if (index != -1) { urlString = urlString.substring(0, index + 1); } return head + urlString; } }