Page 1 of 2 12>
Topic Options
#135326 - 2005-03-11 08:36 PM comma delimited string or array question
BillRamby Offline
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 Offline
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)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#135328 - 2005-03-11 09:31 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you Split() on ',OU=' then you need not worry about commas elsewhere.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135329 - 2005-03-11 09:34 PM Re: comma delimited string or array question
Howard Bullock Offline
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)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#135330 - 2005-03-11 09:38 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Huh?

Just do a double Split(Split()) on ',DC=' first and then on ',OU='. How hard can it be?
Jooel would have no prob to do it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135331 - 2005-03-11 09:42 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
$DN = 'OU=Users,OU=Some Site,DC=somedc,DC=somedc,DC=somedc,DC=some'
$SS = Split(Split($DN,',DC=')[0],',OU=')[1]
$SS ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135332 - 2005-03-11 09:49 PM Re: comma delimited string or array question
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#135333 - 2005-03-11 09:52 PM Re: comma delimited string or array question
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#135334 - 2005-03-14 01:24 PM Re: comma delimited string or array question
BillRamby Offline
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 Offline
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
#135336 - 2005-03-14 02:29 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
yes it would.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135337 - 2005-03-14 02:32 PM Re: comma delimited string or array question
BillRamby Offline
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
#135338 - 2005-03-14 02:43 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
First off, it bugs me that you obfuscate the facts and then come back and change the rules after code has beeen supplied to you. Why don't you spell out all the rules up front in the first place?

Second, it is Howard's code you chose to adopt and I did not bother to analyze it beyond the first weakness of the comma delimiter.

If I knew all the rules, I may answer differently. What different permutations of "some site" can there be and do you always want to peel off only the first part delimited by a space?

Without knowing all the rules... you could check UBound($SiteParts2)>1 and Join() back the second and third (or more) elements... or you could use a combination of Instr() and Substr().
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135339 - 2005-03-14 02:54 PM Re: comma delimited string or array question
BillRamby Offline
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 Offline
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 Offline
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
#135342 - 2005-03-14 03:28 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Still the sour grapes...

What is wrong with using my code?

The part SubStr($SS, 9) will break if you go to Region10 or more!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135343 - 2005-03-14 03:32 PM Re: comma delimited string or array question
BillRamby Offline
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
#135344 - 2005-03-14 03:35 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
DOH!
I should test my code before posting it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135345 - 2005-03-14 03:41 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Dang... had to RTFM.

$SSLeft = Right($SS,Len($SS)-Instr($SS,' '))
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 186 anonymous users online.
Newest Members
dimi575, Drecksnacken, Nlill, webtools321, multiman
17734 Registered Users

Generated in 0.044 seconds in which 0.012 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org