Eliminate Query in Java

Description

The following code shows how to eliminate Query.

Example


// w  w w . j  a  v a 2s.co  m
public class Main {
  public static void main(String[] argv){
    String uri= "http://www.yahoo.com:80/en/index.html?name=joe#first";
    System.out.println(eliminateQuery(uri));
  }
  static public String eliminateQuery(String uri) {
      int idx = uri.indexOf('?');
      if (idx < 0) return uri;
      return uri.substring(0, idx);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode