DEV Community

Discussion on: Daily Challenge #305 - Remove Anchors from URLs

Collapse
 
baenencalin profile image
Calin Baenen • Edited

Java:

class URL {
    private String url = null;
    public URL(String url) {this.url = url;} // The url.
    public String removeAnchor() {
        if(url != null) return url.split("#")[0]; // Get the part before the anchor.
        return "";
    }
}
Enter fullscreen mode Exit fullscreen mode