Ostap Posted January 12, 2018 Share Posted January 12, 2018 Hi, I need to parse a text file extracted from active directory, and string looks like this: CN=Firstname0\, Lastname0 (UserID0),OU=_Marked for deletion,DC=Fabrikam,DC=COM^CN=Firstname1\, Lastname0 (UserID0),OU=Users,OU=EUR,DC=Fabrikam,DC=COM^CN=Firstname2\, Lastname2 (UserID3),OU=Users,OU=EUR,DC=Fabrikam,DC=COM Code is very basic $String0 = "CN=Firstname0\, Lastname0 (UserID0),OU=_Marked for deletion,DC=Fabrikam,DC=COM^CN=Firstname1\, Lastname0 (UserID0),OU=Users,OU=EUR,DC=Fabrikam,DC=COM^CN=Firstname2\, Lastname2 (UserID3),OU=Users,OU=EUR,DC=Fabrikam,DC=COM" MsgBox (0, "$String0", $String0 ) ; returns msgbox with above string $Members = StringSplit ( $String0, "^" ) MsgBox (0, "$Members", $Members ) ; returns empty StringSplit returns empty array no matter what delimiters I try. What I am doing wrong? Link to comment Share on other sites More sharing options...
Floops Posted January 12, 2018 Share Posted January 12, 2018 StringSplit returns an array which can't be displayed using a MsgBox. Use _ArrayDisplay instead. Link to comment Share on other sites More sharing options...
water Posted January 12, 2018 Share Posted January 12, 2018 In case of an error each AutoIt function either sets the return value or macro @error to a value denoting the kind of problem. It is good practice to check this values after each function call. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 12, 2018 Moderators Share Posted January 12, 2018 @Ostap welcome to the forum. As mentioned above, the problem is a combination of trying to use the wrong tool for the job (a MsgBox to display an array) and a lack of error checking. I would suggest in addition that you spend some time reading the help file page for the particular function you plan to use. The examples provided (in this case 3) will show you the proper way to utilize the command to retrieve the results you're after. Earthshine 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
water Posted January 12, 2018 Share Posted January 12, 2018 I do not know which tool you run to extract the data from AD, but AutoIt provides the AD UDF to directly access AD and retrieve the needed information for further processing. For download please check my signature. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Skysnake Posted January 15, 2018 Share Posted January 15, 2018 ; show result, this is quick and dirty ConsoleWrite("result is not array " & $aResult &@CRLF) ; will write result to the console if it is NOT an array IF _IsArray($aResult) Then _ArrayDisplay($aResult) ; will display a popup with array IF IS array Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
water Posted January 15, 2018 Share Posted January 15, 2018 _IsArray doesn't work for StringSplit as this function always returns an array. If the delimiter isn't found then @error is set to 1 and the full string is returned in $aArray[0] or $aArray[1] (depending on the $STR_NOCOUNT flag. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
rootx Posted January 15, 2018 Share Posted January 15, 2018 #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> $String0 = ("CN=Firstname0\, Lastname0 (UserID0),OU=_Marked for deletion,DC=Fabrikam,DC=COM" _ & "^CN=Firstname1\,Lastname0 (UserID0),OU=Users,OU=EUR,DC=Fabrikam,DC=COM" _ & "^CN=Firstname2\, Lastname2 (UserID3),OU=Users,OU=EUR,DC=Fabrikam,DC=COM") $Members = StringSplit ( $String0, "^",2) Dim $Arr[0] For $x = 0 to UBound($Members)-1 ConsoleWrite($Members[$x]&@CRLF) _ArrayAdd($Arr,$Members[$x]) Next _ArrayDisplay($Arr) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 15, 2018 Moderators Share Posted January 15, 2018 @rootx So, you create an array with StringSplit, then cycle through that array to create a second array, then display the second array (which is exactly the same as the $Members array originally returned). Rube Goldberg much? rootx and kylomas 2 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
rootx Posted January 15, 2018 Share Posted January 15, 2018 !!! #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> $String0 = ("CN=Firstname0\, Lastname0 (UserID0),OU=_Marked for deletion,DC=Fabrikam,DC=COM" _ & "^CN=Firstname1\,Lastname0 (UserID0),OU=Users,OU=EUR,DC=Fabrikam,DC=COM" _ & "^CN=Firstname2\, Lastname2 (UserID3),OU=Users,OU=EUR,DC=Fabrikam,DC=COM") $Members = StringSplit ( $String0, "^",2) _ArrayDisplay($Members) For $x = 0 to UBound($Members)-1 ConsoleWrite($Members[$x]&@CRLF) Next Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 15, 2018 Moderators Share Posted January 15, 2018 Just the same @rootx, both _ArrayDisplay and ConsoleWrite are for debugging purposes only. Why double the script's work by using both? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
rootx Posted January 15, 2018 Share Posted January 15, 2018 to show Ostap something useful to understand.. 4 ex debugging. Link to comment Share on other sites More sharing options...
iamtheky Posted January 15, 2018 Share Posted January 15, 2018 you can always put some debug in your debug #include <Array.au3> $String0 = ("CN=Firstname0\, Lastname0 (UserID0),OU=_Marked for deletion,DC=Fabrikam,DC=COM" _ & "^CN=Firstname1\,Lastname0 (UserID0),OU=Users,OU=EUR,DC=Fabrikam,DC=COM" _ & "^CN=Firstname2\, Lastname2 (UserID3),OU=Users,OU=EUR,DC=Fabrikam,DC=COM") $members = StringSplit ( $String0, "^",2) _ArrayDisplay($members , "Array+Console" , "" , 0 , 0 , 0 , 0 , 0 , consolewrite(_ArrayToString($members , @CR))) JLogan3o13 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now