Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string (path of Uri) based on "/"

Wonder if someone could point me in the right direction. What I'd like to achieve is to split a string based upon it having a '/' in it. For example if I had: www.site.com/course/123456/216 in code (c#) I'd like to be able to split the string in code so that 123456 could be assigned to variable param1 and 216 be assigned to param2 (course is the 'friendly' name of the page). If I was to add a third '/' on the string I'd like this to become param3, etc, etc.

Ideally I'd like to be able to put this code somewhere that I could include it on whichever usercontrols I'd need it to work.

like image 886
SxChoc Avatar asked Jul 01 '13 20:07

SxChoc


1 Answers

Uri.Segments maybe what you are looking for:

new Uri("http://www.contoso.com/foo/bar/index.htm#search").Segments

Results in [ "/", "foo/", "bar/", "index.html" ]

like image 194
Alexei Levenkov Avatar answered Sep 30 '22 01:09

Alexei Levenkov