Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract left of the question mark

Tags:

c#

Is there a quick way to grab everything left of the question mark?

http://blah/blah/?blah

to 

http://blah/blah/
like image 488
Rod Avatar asked May 09 '11 20:05

Rod


2 Answers

 Uri uri = new Uri(@"http://blah/blah/?blah");
 string leftPart = uri.OriginalString.Replace(uri.Query,string.Empty); 
like image 143
Bala R Avatar answered Sep 17 '22 23:09

Bala R


Basically, you want to use string.Split:

string url = @"http://blah/blah/?blah";
var parts = url.Split('?');

string bitToLeftOfQuestionMark = parts[0];
like image 26
ChrisF Avatar answered Sep 21 '22 23:09

ChrisF