locked
Find string in array RRS feed

  • Question

  • This might be a silly question but I seem to be stuck with it.

    I am trying to find a string in an array. But in the end when I do the check it says it is false.

    Indexlist

    PS > $IndexListURL.GetType()
    
    IsPublic IsSerial Name                                     BaseType                                                                                                                          
    -------- -------- ----                                     --------                                                                                                                          
    True     True     Object[]                                 System.Array                                                                                                                      
    
    PS > $IndexListURL
    Url                                                   
    ---                                                   
    https://tenancy.sharepoint.com/sites/SiteTest
    https://tenancy.sharepoint.com/sites/SiteBTest   

    ActiveSite

    PS > $ActiveSite.GetType()
    
    IsPublic IsSerial Name                                     BaseType                                                                                                                          
    -------- -------- ----                                     --------                                                                                                                          
    True     False    PSCustomObject                           System.Object                                                                                                                     
    
    PS > $ActiveSite.Url.GetType()
    
    IsPublic IsSerial Name                                     BaseType                                                                                                                          
    -------- -------- ----                                     --------                                                                                                                          
    True     True     String                                   System.Object                                                                                                                     
    
    PS > $ActiveSite.Url
    https://tanancy.sharepoint.com/sites/SiteBTest

    Try and see of String in $ActiveSite.Url exists in $Indexlist

    PS > $IndexListURL.Contains($ActiveSite.Url)
    False

    Would really appreciate a pointer with this.

    TIA




    Thursday, February 20, 2020 3:22 PM

Answers

  • "tenancy" is not "tanancy", for one thing.  Also $IndexListURL is an object containing $IndexListURL.Url.

    Here's an example that works:


    $a = 'https://tenancy.sharepoint.com/sites/SiteTest',
      'https://tenancy.sharepoint.com/sites/SiteBTest'
    $b = 'https://tenancy.sharepoint.com/sites/SiteBTest'
    $a.contains($b)

    True

    • Proposed as answer by jrv Thursday, February 20, 2020 3:34 PM
    • Edited by JS2010 Thursday, February 20, 2020 3:35 PM
    • Marked as answer by GTEM Thursday, February 20, 2020 3:43 PM
    Thursday, February 20, 2020 3:32 PM

All replies

  • "tenancy" is not "tanancy", for one thing.  Also $IndexListURL is an object containing $IndexListURL.Url.

    Here's an example that works:


    $a = 'https://tenancy.sharepoint.com/sites/SiteTest',
      'https://tenancy.sharepoint.com/sites/SiteBTest'
    $b = 'https://tenancy.sharepoint.com/sites/SiteBTest'
    $a.contains($b)

    True

    • Proposed as answer by jrv Thursday, February 20, 2020 3:34 PM
    • Edited by JS2010 Thursday, February 20, 2020 3:35 PM
    • Marked as answer by GTEM Thursday, February 20, 2020 3:43 PM
    Thursday, February 20, 2020 3:32 PM
  • Awesome, thank you for your prompt response.

    Apology with tanancy, Just my fat fingers during overtype. (Good spot though :) )

    Changed it to the following that gave me the result I was looking for

    PS > $IndexListURL.Url.Contains($ActiveSite.Url)
    True

    Thursday, February 20, 2020 3:43 PM