I have an input string which data is coming in the following format:
- “http://testing/site/name/lists/tasks”
- “http://testing/site/name1/lists/tasks”
- “http://testing/site/name2/lists/tasks” etc.,
How can I extract only name, name1, name2, etc. from this string?
Here is what I have tried:
SiteName = (Url.Substring("http://testing/site/".Length)).Substring(Url.Length-12)
It is throwing an exception stating StartIndex cannot be greater than the number of characters in the string. What is wrong with my expression? How can I fix it? Thanks.
A better option will be to use Regex matching/replace
But the following will also work based on the assumption that all the urls will be similar in pattern
The other option will be to use Uri
then breaking down uri parts according to your requirement