Extracts the base URL from the given URL by stripping the query and anchor part.
public class Utils {
public static final String QUERY_CHAR = "?"; //$NON-NLS-1$
public static final String ANCHOR_CHAR = "#"; //$NON-NLS-1$
/**
* Extracts the base URL from the given URL by stripping the query and anchor
* part.
*
* @param url
* URL
* @return URL without the query part
*/
public static String extractBaseUrl(String url) {
if (url != null) {
int queryPosition = url.indexOf(QUERY_CHAR);
if (queryPosition <= 0) {
queryPosition = url.indexOf(ANCHOR_CHAR);
}
if (queryPosition >= 0) {
url = url.substring(0, queryPosition);
}
}
return url;
}
}
Related examples in the same category