I'm Adding strings in loop and for each loop I need to check whether it doesn't cantains /
on its end.
eg www.google.com/
needs to result in www.google.com
but for www.google.com/maps
needs to result in www.google.com/maps
serviceLink.Add(row.LinkService.Replace(Environment.NewLine, " ").Replace("http://",""));
May someone please help me solve thi out?
I thought that .Replace(".com/",".com")
would be enough but it wouldn't handle other domains.
Thank you for your time and answers.
myString = myString.TrimEnd('/');
String str = "www.google.com/";//or any other link
int index=str.Trim().LastIndexOf("/");
if (index == str.Trim().Length - 1)
str=str.Remove(index, 1);
System.String MyStr="http://www.google.com/";
if(MyStr.EndsWith("/"))
{
MyStr = MyStr.Substring(0, MyStr.Length - 1);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.