Jump to content
Sign in to follow this  
VAADAdmin

String Splits

Recommended Posts

VAADAdmin

Below I have a snippet of code. I am using string split to get the distinguished name of a user. (cn=user,ou=accounts,dc=domain,dc=com). I am returning the string and want to strip off the cn=user part to return just the last part of the DN. The problem I am running into is that the number of strings[x] that I have can change with "," as the delimiter. So the subtree can be deeper in Active Directory such as $strDestinationOU[7] and some maybe $strDestinationOU[10]. I would like to just return everything after "cn=user," no matter the length of the remaining string, but I cannot find a solution as of yet.

$strDestinationOU = StringSplit($strUserDN, ',')
            $destinationString = $strDestinationOU[2] & "," & $strDestinationOU[3] & "," & $strDestinationOU[4] & "," & $strDestinationOU[5] & "," & $strDestinationOU[6] & "," & $strDestinationOU[7] & "," & $strDestinationOU[8]
            MsgBox(64,"",$DestinationString)

Share this post


Link to post
Share on other sites
Markus

$strDestinationOU[0] contains the number of splitted strings, so just do:

$strDestinationOU = StringSplit($strUserDN, ',')
For $i=2 To $strDestinationOU[0]
   If $i<$strDestinationOU[0] Then
       $destinationString =$destinationString & $strDestinationOU[$i] & ","
   Else
       $destinationString =$destinationString & $strDestinationOU[$i]
   EndIf
Next
MsgBox(64,"",$DestinationString)
Edited by Markus

"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.