Extract left side of question mark

Is there a quick way to capture everything that remains of a question mark?

http://blah/blah/?blah to http://blah/blah/ 
+6
source share
5 answers
  Uri uri = new Uri(@"http://blah/blah/?blah"); string leftPart = uri.OriginalString.Replace(uri.Query,string.Empty); 
+8
source

Basically, you want to use string.Split :

 string url = @"http://blah/blah/?blah"; var parts = url.Split('?'); string bitToLeftOfQuestionMark = parts[0]; 
+4
source

Try the following:

 string httpString = "http://blah/blah/?blah" int questionMarkLocation = httpString.indexOf('?'); string newString = httpString.Substring(questionMarkLocattion+1); 
+2
source

It looks like you really want to get the scheme, authority, and URI path.

You can use the Uri.GetComponents Method for this:

 var uri = new Uri("http://blah/blah/?blah"); var result = uri.GetComponents( UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped); // result == "http://blah/blah/" 
+2
source

To give an answer to others :

 var url = "http://blah/blah/?blah"; var leftPart = Regex.Match(url, @"[^?]+").Value; 
+1
source

Source: https://habr.com/ru/post/887657/


All Articles