Skip to main content
Participant
January 12, 2011
Answered

How to generate a list or array with fixed values ?

  • January 12, 2011
  • 2 replies
  • 1186 views

Is it possible to create a list or array with fixed values, but with a variable length ?

for example:

var columns = "name, age, function";

var insertParams = generateList( listLen(columns), ",","?" );*

makes: insertParams = "?,?,?"


*(this function doesn't exist. It's just to illustrate what i need)

I know that this function is easely created by creating a loop, but i was wondering if this was possible with just one line of code.

Thanks

    This topic has been closed for replies.
    Correct answer -__cfSearching__-
    if it can generate an array in the same way, that would also be fine.

    Our posts clashed. But I think repeatString() would do the trick. You could either trim the trailing comma with left() or convert it to an array. By default ListToArray() will silently ignore the trailing comma.

    2 replies

    Inspiring
    January 12, 2011

    I am not clear on the question either. But I will take a stab at it. You might be able to use the repeatString() function to repeat a series of characters x times. Though you would have to trim the trailing comma ","

    ie

           <cfset var insertParams  = RepeatString("?,", yourListSize)>

           if yourListSize = 3 the result =>  "?,?,?,"

    Participating Frequently
    January 12, 2011

    I don't really know what your question is.  Are you asking how to make a list?

    var list = "this,is,a,list";

    Participant
    January 12, 2011

    No. My question is if it's possible to generate a list with fixed list values.

    Is there a coldfusion function that does the following:

    var listLength = 5;

    var listSeperator = ",";

    var listItem = "?";

    generateList(listLength, listSeperator, listItem)    that would output "?,?,?,?,?"

    if it can generate an array in the same way, that would also be fine.

    All i need to know if coldfusion has a built-in function that does this.

    -__cfSearching__-Correct answer
    Inspiring
    January 12, 2011
    if it can generate an array in the same way, that would also be fine.

    Our posts clashed. But I think repeatString() would do the trick. You could either trim the trailing comma with left() or convert it to an array. By default ListToArray() will silently ignore the trailing comma.