 |
|
|
manipulate string data
Last Post 01 Jul 2010 06:52 AM by JasonH. 5 Replies.
|
Sort:
|
|
Prev Next |
You are not authorized to post a reply. |
|
| Author |
Messages |
 |
JasonH
 New Member Posts:18

 |
| 30 Jun 2010 03:54 PM |
|
Hello all, I've got a string that I'd like to capture a six character string out of the middle but I've been unable to figure out a way to do this after a short bit of searching around. Here's the string:
employeeNumber=123456,ou=people,dc=nwtraders,dc=com
What I'd like to isolate is just the six digit number after employeeNumber so I'll end up with the string:
123456
Any suggestions are much appreciated. Thanks! Jason
|
|
|
|
|
Marco Shaw (MVP)
 Veteran Member Posts:1643

 |
| 30 Jun 2010 04:32 PM |
|
Without getting into using regular expressions, you can simply do: PS>"employeeNumber=123456,ou=people,dc=nwtraders,dc=com".split("=")[1].split(",")[0] |
|
Marco
*Microsoft MVP - Windows PowerShell
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
*Blog - http://marcoshaw.blogspot.com |
|
|
PoSherLife
 Basic Member Posts:364

 |
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
George Howarth
 Basic Member Posts:360

 |
| 01 Jul 2010 01:58 AM |
|
[Regex]::Match("employeeNumber=123456,ou=people,dc=nwtraders,dc=com", '\d{6}').Value 123456 |
|
|
|
|
JasonH
 New Member Posts:18

 |
| 01 Jul 2010 06:52 AM |
|
Fantastic. Thank you all for the super quick responses. I love the way there are so many different ways to do this. |
|
|
|
|
| You are not authorized to post a reply. |
|
Active Forums 4.3
|
|
 |