header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Easier way to trim a string?
Last Post 06 Jul 2010 10:15 AM by Kingu. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
KinguUser is Offline
New Member
New Member
Posts:14
Avatar

--
06 Jul 2010 09:42 AM
    I have a string that looks like a typical AD object:

    $OrigString = CN=Bob,CN=Users,DC=Office,DC=Local


    So, in order to Isolate the first part of that String (Basically, I want to get 'Bob' from that string).. I do this:

    $NewString = $OrigString.Split("=")[1]
    $NewString = $NewString.Split(",")[0]


    My question:  Is there an 'easier' way to do that?  It's not like what I'm doing is very complicated, but I was just curious...
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    06 Jul 2010 09:57 AM
    $OrigString = "CN=Bob,CN=Users,DC=Office,DC=Local"
    $NewString = $OrigString.Split(",")[0] -replace "CN=",""

    Split() using the comma's breaks each element into its natural format (CN=xxx), then using a simple -replace on the one string within the Split() array completes this task without creating multiple objects and is very simple.
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    KinguUser is Offline
    New Member
    New Member
    Posts:14
    Avatar

    --
    06 Jul 2010 10:15 AM
    Awesome, tip, Thanks!!  I figured there was something I was missing!!
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer