DEV Community

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

Collapse
 
danielt404 profile image
DanielT404

C# solution

class MainClass {

  public static string remove_url_anchor(string url) {
    int anchorFoundAt = url.IndexOf("#", 0, url.Length);
    if(anchorFoundAt == -1) return url;
    return url.Substring(0, anchorFoundAt);
  }

  public static void Main (string[] args) {
    string url = remove_url_anchor("dev.to#about");
    Console.WriteLine(url);
  }
}
Enter fullscreen mode Exit fullscreen mode