1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.net.URL; public class test { public static void main(String[] args) { try { URL url = new URL(args[0]); String protocol = url.getProtocol(); String result = args[0].replaceFirst(protocol + ":", ""); if (result.startsWith("//")) { result = result.substring(2); } System.out.println(result); } catch (Exception e) { System.out.println(e); } } } |
1 2 |
String myString = "http://www.abc.com"; myString.replace("http://","").replace("http:// www.","").replace("www.",""); |