0

I'm Adding strings in loop and for each loop I need to check whether it doesn't cantains / on its end.

e.g. 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.

1
  • 1
    You could use the Uri class instead of parsing the string yourself. What if it starts with "https://"? Commented Dec 2, 2013 at 10:23

3 Answers 3

12
myString = myString.TrimEnd('/');
Sign up to request clarification or add additional context in comments.

Comments

1
    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);

Comments

0
System.String MyStr="http://www.google.com/";
if(MyStr.EndsWith("/"))
{
   MyStr = MyStr.Substring(0, MyStr.Length - 1);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.