题目
Complete the function/method so that it returns the url with anything after the anchor (#) removed.
Examples:
Kata.RemoveUrlAnchor("www.codewars.com#about") => "www.codewars.com"
Kata.RemoveUrlAnchor("www.codewars.com?page=1") => "www.codewars.com?page=1"
代码
using System;
public static class Kata
{
public static string RemoveUrlAnchor(string url)
{
foreach(char c in url){
if(!url.Contains('#')){
return url;
}
}
string output="";
for(int i=0;i<url.Length;i++){
if(url[i]=='#'){
output=url.Remove(i,url.Length-i);
}
}
return output;
}
}