给定一个url获取host

/**
  * get host of an url
  * @param urlString
  * @return
  */
 public static String getHost(String urlString) {
  int index = urlString.indexOf("://");
  if (index != -1) {
   urlString = urlString.substring(index + 3);
  }
  index = urlString.indexOf("/");
  if (index != -1) {
   urlString = urlString.substring(0, index);
  }
  return urlString;
 }

你可能感兴趣的:(host)