Skip to main content
Known Participant
August 8, 2008
Question

Problem using ListToArray and ReplaceList

  • August 8, 2008
  • 6 replies
  • 591 views
I receive a single string value from a LDAP query which contains all the members of a group.

This result is saved to a variable called "member"
--------------------------------------------------------------------------------------------
CN=Cattel\, Joseph A.,OU=Applications,OU=Information Systems,DC=ha2000,DC=com, CN=Morand\, Douglas,OU=Applications,OU=Information Systems,DC=ha2000,DC=com, CN=Sonn\, Jr.\, David E.,OU=Applications,OU=Information Systems,DC=ha2000,DC=com, CN=Simons\, Steven F.,OU=Applications,OU=Information Systems,DC=ha2000,DC=com, CN=Reddy\, Bhavana,OU=Applications,OU=Information Systems,DC=ha2000,DC=com, CN=Platt\, Betsy,OU=Applications,OU=Information Systems,DC=ha2000,DC=com, CN=Normandin\, Patricia,OU=Patient Registration,DC=ha2000,DC=com, CN=Maillet\, Sue,OU=Applications,OU=Information Systems,DC=ha2000,DC=com, CN=Campbell\, Margaret,OU=Applications,OU=Information Systems,DC=ha2000,DC=com

I want to create an array from this list so I can loop through it an make separate LDAP calls with each user so I add in a ";" character at the end of each line.
<cfset myArrayList = ListToArray(ReplaceList(member,"=com, ","=com;"),";")>

Then I loop through my newly created array.
<cfloop from="1" to=#ArrayLen(myArrayList)# step="1" index="i">
#myArrayList # <br />
</cfloop>

The problem I'm having is this is what I'm getting for the array values:
------------------------------------------------------------------------------------------------------------------------------
CN=Cattel\,JosephA.,OU=Applications,OU=InformationSystems,DC=ha2000,DC=com
,CN=Morand\,Douglas,OU=Applications,OU=InformationSystems,DC=ha2000,DC=com
,CN=Sonn\,Jr.\,DavidE.,OU=Applications,OU=InformationSystems,DC=ha2000,DC=com
,CN=Simons\,StevenF.,OU=Applications,OU=InformationSystems,DC=ha2000,DC=com
,CN=Reddy\,Bhavana,OU=Applications,OU=InformationSystems,DC=ha2000,DC=com
,CN=Platt\,Betsy,OU=Applications,OU=InformationSystems,DC=ha2000,DC=com
,CN=Normandin\,Patricia,OU=PatientRegistration,DC=ha2000,DC=com
,CN=Maillet\,Sue,OU=Applications,OU=InformationSystems,DC=ha2000,DC=com
,CN=Campbell\,Margaret,OU=Applications,OU=InformationSystems,DC=ha2000,DC=com

Why is there a "," character at the beginning of each of my array elements except the first one? Is it because of the ListToArray? I would have thought that my replacelist function would have removed the "," at the end of each element.
    This topic has been closed for replies.

    6 replies

    Inspiring
    August 8, 2008
    Dan Bracuk wrote:
    > loop through entire list using comma delimiters ...
    > Each element will be a list with an equal sign delimiter.

    You may have to add some extra logic. Unfortunately, the CN value appears to contain commas.

    CN=Cattel\, Joseph A.,OU=Applications,....
    dmorand17Author
    Known Participant
    August 8, 2008
    I'll give that a shot and see what I get. Thanks Dan!
    dmorand17Author
    Known Participant
    August 8, 2008
    Thanks! I'll keep that in mind
    dmorand17Author
    Known Participant
    August 8, 2008
    I thought I had to create an array from the list I had in order to loop through the specific elements.

    I am using this code now, and am able to get the correct array elements
    <cfset newMember=#Replace(member,"=com, ","=com;",'all')#>
    <cfset myArrayList = ListToArray(newMember,";")>
    Inspiring
    August 8, 2008
    dmorand17 wrote:
    > I thought I had to create an array from the list I had in order to loop through the specific elements.

    Possibly. I only examined the syntax, not the logic.

    > <cfset newMember=#Replace(member,"=com, ","=com;",'all')#>

    While the code will work either way, the # signs are not needed. Also keep in mind Replace is case sensitive.

    Inspiring
    August 8, 2008
    dmorand17 wrote:
    > <cfset myArrayList = ListToArray(ReplaceList(member, "=com, ","=com;"),";")>
    > Why is there a "," character at the beginning of each of my array elements except the first one?

    You are using the wrong function. The second parameter of ReplaceList is Comma-delimited list of substrings for which to search. So "=com, " is treated as a list of values: "=com" and "(a space character)".

    Assuming you actually need an array, try the Replace or ReplaceNoCase function instead.
    Inspiring
    August 8, 2008
    If the intent is to make separate ldap calls for each user, why bother with the array? Why not just loop through the list you have and look for the element.