#135326 - 2005-03-11 08:36 PM
comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
I have a comma delimited string or array received from the getuserou UDF. The returned string looks like this:
OU=Users,OU=Some Site,DC=somedc,DC=somedc,DC=somedc,DC=some
What I need from the string is the second delimited value, "OU=Some Site". From there I need to strip the OU= and further break it down into "Some" and "Site" and assign each to a variable.
I've looked at the manual at ASCAN and SPLIT, but can't quite see how to make them do the job I need. Any pointers in the right direction would be appreciated.
Regards Bill R.
|
Top
|
|
|
|
#135327 - 2005-03-11 09:16 PM
Re: comma delimited string or array question
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Code:
$a = "OU=Users,OU=Some Site,DC=somedc,DC=somedc,DC=somedc,DC=some"
; This works if you never include commas in any OU name.
$DNparts = split($a, ",")
? $DNparts[1]
$sitename = SubStr($DNparts[1], 4)
? $sitename
$SiteParts = split($sitename)
? $SiteParts[0]
? $SiteParts[1]
;Bring it altogether
$SiteParts2 = split(SubStr(split($a, ",")[1], 4))
? $SiteParts2[0]
? $SiteParts2[1]
Oh ya... Welcome to the board.
Edited by Howard Bullock (2005-03-11 09:20 PM)
|
Top
|
|
|
|
#135329 - 2005-03-11 09:34 PM
Re: comma delimited string or array question
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
True, but that will not automatically separate the site value from the ",DC=" domain strings. You will then need to worry about commas in the site OU name when parsing it from the DC= string.
Edited by Howard Bullock (2005-03-11 09:35 PM)
|
Top
|
|
|
|
#135332 - 2005-03-11 09:49 PM
Re: comma delimited string or array question
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
It isn't... (PITA time) I guess that works for this particular example. There are many ways to get the goal line.
|
Top
|
|
|
|
#135333 - 2005-03-11 09:52 PM
Re: comma delimited string or array question
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I like it. This is a better solution as commas do not interfere.
|
Top
|
|
|
|
#135334 - 2005-03-14 01:24 PM
Re: comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
Wow, lot of input over the weekend. I have my work cut out for me. Thanks everyone.
Regards Bill
|
Top
|
|
|
|
#135335 - 2005-03-14 02:18 PM
Re: comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
Ok, I want to understand this as well as use it, so I hope you don't mind some teaching.
Ok I get this part. Setting the variable
Quote:
Code:
$a = "OU=Users,OU=Some Site,DC=somedc,DC=somedc,DC=somedc,DC=some"
Ok, here you are taking the variable and making it an array (I think) of it's split parts and getting "Ou=Some Site". Does the split start at zero or one? I'm guessing 0 because the second value, which is the one needed, appears to be one here.
Quote:
Code:
$DNparts = split($a, ",") ? $DNparts[1]
Ok, I understand what your doing here. Your taking "OU=Some Site" and stripping off the ",OU=" as represented by the "4", as in counting from left to right ",OU=" equals 4 characters.
Quote:
Code:
$sitename = SubStr($DNparts[1], 4) ? $sitename
Ok, I got this I think. This is splitting "Some Site" into "Some" and "Site"
Quote:
Code:
$SiteParts = split($sitename) ? $SiteParts[0] ? $SiteParts[1]
This seems a repeat of the section above. What am I missing here?
Quote:
Code:
$SiteParts2 = split(SubStr(split($a, ",")[1], 4)) ? $SiteParts2[0] ? $SiteParts2[1]
Oh, and one further question. Let say "OU=Some Site" actually looked like this: OU=Region1 Houston Texas And I would need SiteParts[0] and SiteParts[1] to be reflected this way: SiteParts[0] would equal "Region1" SiteParts[1] would equal "Houston Texas" Would the space in "Houston Texas" cause problems?
Thanks again for the help.
Regards Bill
|
Top
|
|
|
|
#135337 - 2005-03-14 02:32 PM
Re: comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
So, would the answer be to take "$Sitename", do a substr replacing character 8 with a comma, and repeat the process?
Regards
Bill
Edited by BillRamby (2005-03-14 02:34 PM)
|
Top
|
|
|
|
#135339 - 2005-03-14 02:54 PM
Re: comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
No obfuscation was intended. It just didn't occure to me at the time of my first post. Different AD names in different regions. I personally work in a region that is just one word and that influenced my question. My error.
That said, some regions can have up to three words, e.g "New York City", therefore, I need to split the first section from the rest.
|
Top
|
|
|
|
#135340 - 2005-03-14 03:10 PM
Re: comma delimited string or array question
|
Les
KiX Master
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
Don't mind me... sour grapes cuz you chose Howard's coode and I haven't had my 3rd cup of coffee yet.
Code:
break on $DN = 'OU=Users,OU=Region1 New York City,DC=somedc,DC=somedc,DC=somedc,DC=some' $SS = Split(Split($DN,',DC=')[0],',OU=')[1] $SS ?
$SS1 = Left($SS,Instr($SS,' ')-1) $SSLeft = Right($SS,Instr($SS,' ')+1)
'SS1 = ['+$SS1+']' ? 'SSLeft = ['+$SSLeft+']' ?
THis is still overly optimistic code. It would break if there are more OUs. For that you should check UBound().
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
Top
|
|
|
|
#135341 - 2005-03-14 03:20 PM
Re: comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
Les, your code threw me for a moment (the ? after $ SS) but once tried it does appear to work with a lot less code. Using a combination of your and Howards code:
Code:
$OU = 'OU=Users,OU=Region2 New York City,DC=somedc,DC=somedc,DC=somedc,DC=some'
$SS = Split(Split($OU,',DC=')[0],',OU=')[1]
? $SS
$site = SubStr($SS, 9)
? $site
Returns:
Region2 New York City
New York City
Question for you. What does the apostrophe in your code do?
Whoops, just figured it out. Early morning and only two cups here so far.
Edited by BillRamby (2005-03-14 03:22 PM)
|
Top
|
|
|
|
#135343 - 2005-03-14 03:32 PM
Re: comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
Nothing wrong with the code. I just didn't see the value expressed when I ran it in a window until I changed
$SS ? to ? $SS
Actually I'm checking your new code now. I get the results of: SS1 = [Region1] SSLeft = [York City]
Working on where "New" went now.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 918 anonymous users online.
|
|
|