Removing part of a string - C # [duplicate]

3

How can I remove my last characters from a string until I reach a certain character? For example:

string url="www.google.com/test";

I needed to remove the test pad until I got the "/" character. I would like to play the rest in another variable, just like this:

string result="www.google.com";

Is this possible? Thank you!

    
asked by anonymous 20.09.2015 / 21:39

1 answer

4

One option is to use Split .

string url = "www.google.com.br/teste";
string resultado = url.Split('/')[0];


Or better than that, use Substring .

string resultado = url.Substring(0,url.IndexOf('/'));
    
20.09.2015 / 21:44