Splitting a CSV list

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Splitting a CSV list

    I have the following type of data in a page and I need to be able to pull each
    and every CN value without the CN or anything behind it.

    CN=CompStaff,OU=MyOU,DC=MyDC,DC=com,

    Is there a way to do this in CF 4.5? I know we are behind times but we are
    about to upgrade this year to MX and I ned to be able to do this now. Thaks for
    any help you can provide.

    jgrantham Guest

  2. Similar Questions and Discussions

    1. Splitting a List control into columns
      I have the following XML structure as data provider for List control: <?xml version="1.0" encoding="UTF-8"?> <europe> <areas> <area label="West...
    2. splitting a PDF file
      Does anyone know if or how to split a multiple page PDF file into single page PDF files in Acrobat 7? I heard this could be done without purchasing...
    3. Intelligent PDF Splitting
      Does anyone have information about intelligent PDF splitting, using either command line or applescript?
    4. Splitting Comma delimited list
      Hello everyone, I use the following to split a comma delimited list and get varying results and I don't understand why. my count of the...
    5. Splitting OR Regex
      On Thu, 30 Oct 2003 23:37:55 -0500, Scott, Joshua wrote: This is a FAQ: perldoc -q delimit -- Tore Aursand <tore@aursand.no>
  3. #2

    Default Re: Splitting a CSV list

    I can't remember, does 4.5 not support RegEx? I assume not, so you would have
    to loop:

    <cfset aMyCNs = ArrayNew(1)>
    <cfset foo = "CN=CompStaff,OU=MyOU,DC=MyDC,DC=com,">

    <cfloop index="i" list="#foo#" delimiter=",">
    <cfif Left(i, 3) IS "CN=">
    <cfset x = ArrayAppend(aMyCNs, ReplaceNoCase(i, "CN=", ""))>
    </cfif>
    </cfoop>

    You end up with an array of your CNs. You could use a list instead.

    blewis Guest

  4. #3

    Default Re: Splitting a CSV list

    This would work:

    <cfset TheStr = "CN=CompStaff,OU=MyOU,DC=MyDC,DC=com,CN=MyStaff,CN =YourStaff">

    <cfloop index="ii" list="#TheStr#">
    <cfif NOT Compare("CN",ListFirst(ii,"="))>
    <cfoutput>The DC value is #ListLast(ii,"=")#<br></cfoutput>
    </cfif>
    </cfloop>

    OldCFer Guest

  5. #4

    Default Re: Splitting a CSV list

    Your solution is REAL close to what I want.

    I am running a CFLDAP query named "Groups" where it searches for the groups a
    person belongs to based on a variable submitted to the page thus the
    #Groups.memberOf#. It seems to be listing only the first one or two groups
    this person belongs to. Any ideas on how to make it work? I'm REAL new to CF
    and havae this project that needs to be done and this is all that is holding me
    back.

    Here is the code after modifying it for my situation:

    <cfset TheStr = "#Groups.memberOf#">
    <cfloop index="ii" list="#TheStr#">
    <cfif NOT Compare("CN",ListFirst(ii,"="))>
    <td align="left" width="30%">#ListLast(ii,"=")#</td><br>
    </cfif>
    </cfloop>

    jgrantham Guest

  6. #5

    Default Re: Splitting a CSV list

    Here is the output I'm getting if I just do a #Groups.memberOf# :

    CN=Computer Staff dummyOffice,OU=Distribution
    Lists,OU=dummyOffice,DC=dummy,DC=com,
    CN=eCopyScanner,OU=dummyOffice,DC=dummy,DC=com, CN=Antigen
    dummyOffice,OU=Distribution Lists,OU=dummyOffice,DC=dummy,DC=com,
    CN=JaxCompStaff,OU=dummyOffice,DC=dummy,DC=com, CN=Docs
    Users,CN=Users,DC=dummy,DC=com, CN=AV,OU=dummyOffice,DC=dummy,DC=com,
    CN=P10TRNG,OU=dummyOffice,DC=dummy,DC=com, CN=Personnel Update,OU=Distribution
    Lists,OU=dummyOffice,DC=dummy,DC=com, CN=OWA Secure
    users,CN=Users,DC=dummy,DC=com, CN=CMS BASIC,OU=CMS,DC=dummy,DC=com,
    CN=SpyBot,OU=dummyOffice,DC=dummy,DC=com,
    CN=Verizon,OU=dummyOffice,DC=dummy,DC=com, CN=Jackson Backup,OU=Distribution
    Lists,OU=dummyOffice,DC=dummy,DC=com, CN=Computer Staff
    All,OU=dummyOffice,DC=dummy,DC=com

    How can I sort through this and just pull the values after CN= without the OU
    and DC values? This is what I'm trying to do. The code submitted above only
    list two groups but as you can see, there are a lot more than that.

    jgrantham Guest

  7. #6

    Default Re: Splitting a CSV list

    How about this:



    <cfset TheStr = "#Groups.memberOf#">
    <cfloop index="ii" list="#TheStr#">
    <cfif ii contains "CN=">
    <td align="left" width="30%">#Replace(ii,"CN=","")#</td>
    </cfif>
    </cfloop>

    eastinq Guest

  8. #7

    Default Re: Splitting a CSV list

    That's a little closer. I now get the whole list of groups for the user but
    they are all in a straight line. Any ideas now on how to get it to put each one
    on a seperate line inside a table? The internals of the table are already
    inside a cfoutput tag so I don;t think I could nest them could I?

    Here is the code I have already for the table:


    <table border=0 cellspacing=2 cellpadding=2 width="100%">
    <cfoutput query="results">
    <tr>
    <th colspan="4" align="center"><font color="336600"><b>Active Dirctory
    Information for: #displayName#</b></font></th>
    </tr>
    <tr>
    <td width="100%" colspan="4"><hr width="100%"></td>
    </tr>
    <tr>
    <td width="22%" align="right"><font color="336600"><b>Distinguished Name:
    </b></font></td>
    <td colspan="4"><font color="black">#dn#</font></td>
    </tr>
    <tr>
    <td width="22%" align="right"><font color="336600"><b>Account
    Created:</b></font> </td>
    <cfset AccCreatedYear = Left(whenCreated,4)>
    <cfset AccCreatedMonth = Mid(whenCreated,5,2)>
    <cfset AccCreatedDay = Mid(whenCreated,7,2)>
    <td colspan="4"><font color="black">#MonthAsString(AccCreatedMonth)#
    #AccCreatedDay#, #AccCreatedYear#</font></td>
    </tr>
    <tr>
    <td width="22%" align="right"><font color="336600"><b>Account
    Changed:</b></font> </td>
    <cfset AccChangedYear = Left(whenChanged,4)>
    <cfset AccChangedMonth = Mid(whenChanged,5,2)>
    <cfset AccChangedDay = Mid(whenChanged,7,2)>
    <td colspan="4"><font color="black">#MonthAsString(AccChangedMonth)#
    #AccChangedDay#, #AccChangedYear#</font></td>
    </tr>
    <tr>
    <td width="100%" colspan="4"><hr width="100%"></td>
    </tr>
    <tr>
    <td align="right" width="22%"><font color="336600"><b>User
    ID:</b></font></td>
    <td align="left" width="30%"><font color="black">#sAMAccountName#</font></td>
    <td align="right" width="22%"><font
    color="336600"><b>Description:</b></font></td>
    <td align="left" width="30%"><font color="black">#Description#</font></td>
    </tr>
    <tr>
    <td align="right" width="22%"><font
    color="336600"><b>Department:</b></font></td>
    <td align="left" width="30%"><font color="black">#Department#</font></td>
    <td align="right" width="22%"><font color="336600"><b>Telephone
    Number:</b></font></td>
    <td align="left" width="30%"><font
    color="black">#telephoneNumber#</font></td>
    </tr>
    <tr>
    <td width="100%" colspan="4"><hr width="100%"></td>
    </tr>
    <tr>
    <td align="right" width="22%"><font color="336600"><b>Account
    Locked:</b></font></td>
    <td align="left" width="30%"><cfif #lockoutTime# EQ "0"><font
    color="black">No</font><cfelse><font color="red">Yes</font></font></cfif></td>
    <td align="right" width="22%"><font color="336600"><b>Account
    Disabled:</b></font></td>
    <td align="left" width="30%"><cfif #userAccountControl# EQ "512"><font
    color="black">No</font><cfelse><font color="red">Yes</font></font></cfif></td>
    </tr>
    <tr>
    <td align="right" width="22%"><font color="336600"><b>Bad
    Logins:</b></font></td>
    <td align="left" width="30%"><cfif #badPwdCount# EQ "0"><font
    color="black">#badPwdCount#</font><cfelse><font
    color="red">#badPwdCount#</font></cfif></td>
    <td align="right" width="22%"><font color="336600"><b>Max/Attempts
    Left:</b></font></td>
    <td align="left" width="30%"><font
    color="black">#lockoutThreshold#</font></td>
    </tr>
    <tr>
    <td width="100%" colspan="4"><hr width="100%"></td>
    </tr>
    <tr>
    <td align="right" width="22%"><font color="336600"><b>Home
    Directory:</b></font></td>
    <td align="left" width="30%"><font color="black">#HomeDirectory#</font></td>
    <td align="right" width="22%"><font color="336600"><b>Home
    Drive:</b></font></td>
    <td align="left" width="30%"><font color="black">#homeDrive#</font></td>
    </tr>
    <tr>
    <td align="right" width="22%">Member Of:</td>
    <cfset TheStr = "#Groups.memberOf#">
    <cfloop index="ii" list="#TheStr#">
    <cfif ii contains "CN=">
    <td align="left" width="30%">#Replace(ii,"CN=","")#<br></td>
    </cfif>
    </cfloop>
    </tr>
    </cfoutput>
    </table>

    jgrantham Guest

  9. #8

    Default Re: Splitting a CSV list

    I FINALLY DID IT!!!! Hope this helps someone else down the road. Here is the
    solution:

    <tr>
    <td align="right" width="22%" valign="top"><font color="336600"><b>Member
    Of:</b></font></td>
    <td width="30%" align="left">
    <table width="100%">
    <cfset TheStr = "#Groups.memberOf#">
    <cfloop index="ii" list="#TheStr#">
    <cfif ii contains "CN=">
    <tr>
    <td align="left" width="30%"><font
    color="black">#Replace(ii,"CN=","")#</font></td>
    </tr>
    </cfif>
    </cfloop>
    </table>
    </td>
    </tr>

    jgrantham Guest

  10. #9

    Default Re: Splitting a CSV list

    Sorry! I had to nest another table inside the <td> tag to get it to wrap the group names to a new line for every group.
    jgrantham Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139