protected static String normalizeUrlEnding(String link){
  if (link.indexOf("#") > -1)   link=link.substring(0,link.indexOf("#"));
  if (link.endsWith("?"))   link=link.substring(0,link.length() - 1);
  if (link.endsWith("/"))   link=link.substring(0,link.length() - 1);
  return link;
}

protected static String normalizeUrlEnding ( String link ) { if ( link . indexOf ( "#" ) > - 1 ) link = link . substring ( 0 , link . indexOf ( "#" ) ) ; if ( link . endsWith ( "?" ) ) link = link . substring ( 0 , link . length ( ) - 1 ) ; if ( link . endsWith ( "/" ) ) link = link . substring ( 0 , link . length ( ) - 1 ) ; return link ; }
normalizes a url string by removing anchor part and trailing slash
