locked
Extract the last site address from an HTTP string in SharePoint 2007 RRS feed

  • Question

  •  Does anyone have any suggestions on how to pull only the last site address from an HTTP string?

     

    I need to capture the last site address from an IP Address string.

    i.e. http://SPsite1/SPsite2/SPsite3/SPsite4/SPsite5/SPsite-Last 

    I am able to perform this task in Excel with a substitute command:

    =TRIM(RIGHT(SUBSTITUTE(SiteID,"/",REPT(" ",LEN(SiteID))),LEN(SiteID))) 

    Results: SPsite-Last

    But to my GREAT disappointment, Substitute does not work in SharePoint (We are running the free version, 2007)

    Do you have any ideas/solutions for this conundrum?

      

    Best regards,

    Alan

    Thursday, January 12, 2012 12:45 AM

Answers

  • Hi, you can perform javascript functions as well for getting site address.
    Anil
    • Marked as answer by Wayne Fan Monday, January 23, 2012 7:47 AM
    Thursday, January 19, 2012 8:25 AM

All replies

  • Hi, you split it by '/' use strin splite method

    string url=http://SPsite1/SPsite2/SPsite3/SPsite4/SPsite5/SPsite-Last

    string[] arrayString=url.split("/");

    string totalString=arrayString[arrayString.length-1];


    Anil
    Thursday, January 12, 2012 4:58 AM
  • Hello Alan,

    The snippet suggested by Anil should fetch the last site name.

    But performing a split operation and fetching the last item from the array is a slow process. We just need the last site name, so no need to split the string. Alternatively you can try the below cod, which doesn't use array. It just gets name after the last occurrence of '/'

                String strUrl = "http://SPsite1/SPsite2/SPsite3/SPsite4/SPsite5/SPsite-Last";
                String strLastSite = strUrl.Substring(strUrl.LastIndexOf('/')+1);
    


     


    Ram Prasad Meenavalli | MCTS SharePoint 2010 | MCPD SharePoint 2010
    Thursday, January 12, 2012 5:10 AM
  • Hi, i agree with ram and you can modify my code as like this even

    string url="http://SPsite1/SPsite2/SPsite3/SPsite4/SPsite5/SPsite-Last";
    
    string arrayString = url.Split('/').Last();



    Anil
    Thursday, January 12, 2012 7:19 AM
  • Hello Anil,

    Even in your modified code the same operations are being performed, ie., a split operation (which gives an array) and your are getting the last item in the array. So, processing wise it is the same...

    There is no need to split the string in this case. So, its better to use the SubString() operation as I suggested in my previous post


    Ram Prasad Meenavalli | MCTS SharePoint 2010 | MCPD SharePoint 2010
    Thursday, January 12, 2012 7:28 AM
  • I am not a sharepoint expert.  I am stuck in the calcuate box of a sharepoint site.  I could not get "string" to work at that level. 

    Are these SQL commandes, by chance?

     

    Is there a way do do it in a calculate column type?

     

    Thanks

    Thursday, January 19, 2012 12:35 AM
  • Hi, you can perform javascript functions as well for getting site address.
    Anil
    • Marked as answer by Wayne Fan Monday, January 23, 2012 7:47 AM
    Thursday, January 19, 2012 8:25 AM