Creating a 2dm array from a list

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Creating a 2dm array from a list

    I have a list of hrefs from three different sites which I have then stored into
    a 1dm array. There are around 40 elements (href's)in the 1dm array. To manage
    the hrefs more efficiently Im trying to create a 2dm array from the list. Where
    the first dimension is the site and the second element are the links within
    each site (hrefs). Is this possible? And if so how? (Confused) Thanks in
    advance

    samb1 Guest

  2. Similar Questions and Discussions

    1. List from array .as
      in this code ... the list is reading from Array ... but i can not display the name of each of them... ... if you click the button, and then...
    2. array -> list
      Is there a way to convert an array to a (parameter-)list? I often find myself doing things like: year,mon,day,hour,minute =...
    3. [PHP] Array to List
      All, Thanks for your help, but this shouldn't be so freaking hard to do. <sigh> 1) I have a multiple select input on one page that is populated...
    4. Array to List
      Hello, Coming from ColdFusion, this is difficult. CF has an ArrayToList() function. I can't find anything similar in PHP. I'm building a list...
    5. list question (creating one list out of many)
      Actually it would be: on parselist gList,whichList thisMany = which.count -- you don't want to be counting the list at each repeat loop repeat...
  3. #2

    Default Re: Creating a 2dm array from a list

    Tell me more about the structure of your list. Is it like site1,href1,site1,href2,site2,href3,...?
    jdeline Guest

  4. #3

    Default Re: Creating a 2dm array from a list

    Yes the structure of the list is href=webite1?id01 href=webite1?id02
    href=webite1?id03 href=webite2?id01 href=webite2?id02 href=webite3?id01
    href=webite1?id02 etc What I have done is loop over 3 different index pages
    and then use 3 different regex to parse each index page for specific links.
    Those links have then been added straight into a 1dm array. Here is some of y
    code: <cfset xmlObj = xmlParse( xmlString ) /> <!---Loop through the XML
    doc elements---> <cfloop from='1' to='#arrayLen( xmlObj.xmlRoot.xmlChildren
    )#' index='i'> <!---HTTP Call each site index attribute from the XML--->
    <cfhttp method='get' URL='#Trim(xmlObj.xmlRoot.site.xmlAttributes.index )#'
    ResolveURL='no'> <cfset StartPos = 1> <cfloop condition ='True'>
    <!---Parse the site index pages for job links---> <cfset Match =
    REFindNoCase(#Trim(xmlObj.xmlRoot.site.parse.xmlAt tributes.re)#,
    cfhttp.FileContent, StartPos, True)> <cfif Match.pos[1] EQ 0>
    <cfbreak> <cfelse> <cfset StartPos = Match.pos[1] +
    Match.len[1]> <cfset Foundlinks = Mid(cfhttp.FileContent, Match.pos[1],
    Match.len[1])> <cfset StripLinks =
    #REReplaceNoCase(#Mid(cfhttp.FileContent, Match.pos[1], Match.len[1])#,'=['']',
    'http://www.rspb.org.uk/vacancies/index.asp', 'ALL')#>---> </cfif>
    </cfloop> <!---Store the list of FoundLinks into the Links Array--->
    <cfset LinksArray = ListToArray(StripLinks)>

    samb1 Guest

  5. #4

    Default Re: Creating a 2dm array from a list

    Is the list comma delimited? In other words, is it like the list below?

    href=webite1?id01,
    href=webite1?id02,
    href=webite1?id03,
    href=webite2?id01,
    href=webite2?id02,
    href=webite3?id01,
    href=webite1?id02

    If so, code something like that shown below might work.



    <CFSET sites = ArrayNew(2)>

    <CFSET n = 1>
    <CFLOOP LIST="siteList" INDEX="i">
    <CFSET found = Find("?", i)>
    <CFSET sites[n][1] = Mid(i, 1, found - 1)>
    <CFSET sites[n][2] = Mid(i, found + 1, 999)>
    <CFSET n = n + 1>
    </CFLOOP>

    jdeline Guest

  6. #5

    Default Re: Creating a 2dm array from a list

    Thanks for that jdeline but I get an error when trying to dump '#sites[n][1]#'
    Parameter 3 of function Mid which is now -1 must be a non-negative integer
    The error occurred in C:\CFusionMX\wwwroot\Project\1.cfm: line 35 33 :
    <CFLOOP LIST='StripLinks' INDEX='i'> 34 : <CFSET found = Find('?',
    i)> 35 : <CFSET sites[n][1] = Mid(i, 1, found -1)> 36 : <CFSET
    sites[n][2] = Mid(i, found + 1, 999)> 37 : <CFSET n = n + 1> Any
    ideas? Thanks

    samb1 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