Jump to content

Recommended Posts

Posted

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? 

Posted

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

 

  • Moderators
Posted

@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.

"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!

Posted

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

 

Posted
; 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?

Posted

_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

 

Posted
#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)

 

  • Moderators
Posted

@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?

"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!

Posted

!!! :P

#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

 

Posted

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)))

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...