 |
|
|
Easier way to trim a string?
Last Post 06 Jul 2010 10:15 AM by Kingu. 2 Replies.
|
Sort:
|
|
Prev Next |
You are not authorized to post a reply. |
|
| Author |
Messages |
 |
Kingu
 New Member Posts:14

 |
| 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...
|
|
|
|
|
PoSherLife
 Basic Member Posts:364

 |
| 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 |
|
|
Kingu
 New Member Posts:14

 |
| 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
|
|
 |