Hi,
Working with URLs and splitting them to find the parts of the URL that we need. This was a question I asked a bit ago, made some progress, but am stuck again.
Looking to take out a number of characters before a certain web address.
Essentially the current web address I’m trying to split is: https://blah.website.com/segment1/segment2/segment3/unusableinformation1/unusableinformation2/
However, instead of just https://blah.website there could be more than one string of text and periods before website.com
They range from blah.website.com to blah.blah.website.com to blah.blah.blah.website.com
I’d like to make 5 separate URLs from this
- website.com/segment1/
- website.com/segment1/segment2/
- https://website.com/
- https://website.com/segment1/
- https://website.com/segment1/segment2/
This is currently the code I’m working with:
string url = $URL$;
try{
string[] urlSegments = url.Split(’/’);
if(urlSegments[4] != null){
string topURL = urlSegments[1] + urlSegments[2] + ‘/’ + urlSegments[3] + ‘/’;
}else{
string topURL = “#VALUE!”
}
}catch{}
return topURL;
Would need to split not only at the ‘/’ level, but also at the ‘.’ level, while taking into account the varying number of “blahs” before website.com