i have a bunch of url and some of them are optiona...
# lucee
g
i have a bunch of url and some of them are optional, i am trying to loop over them and if they exists and defined, i want to use only that, my only concern right now is the placement of ? and & operator where i am messing up the code
z
trycf.com please post code, how on earth do you expect anyone to answer that question?
a
Agreed post some code of what you've got so far
g
i tried this
Copy code
public any function StructToQueryString(struct) {
    var qstr = "";
    var delim1 = "=";
    var delim2 = "&";

    switch (ArrayLen(Arguments)) {
        case "3":
        delim2 = Arguments[3];
        case "2":
        delim1 = Arguments[2];
    }
        
    for (key in struct) {
        if (isDate(key)) {
            qstr = ListAppend(qstr, URLDecode(LCase(key)) & delim1 & URLDecode(struct[key]), delim2);
            dump(qstr); abort;
        } else {
            qstr = ListAppend(qstr, URLEncodedFormat(LCase(key)) & delim1 & URLEncodedFormat(struct[key]), delim2);
        }
    }
    return qstr;
    }
}
but date is not getting decoded
a
Well. Did you actually check what value
key
has? IE: did you do any debugging as to why the code around the date stuff might not be working the way you want? Also... you only specify one parameter to your function, but you then actually use up to three of them. Just to keep your code clear, you should be specifying all the parameters. Because it's pretty hard to work out why you have written this code the way you have, with the messing around with the delimiters you're doing. Also(2)... does your function really return any? Or does it return a string? Even the function says it returns a string in its name, so then the return type should also be a string.
g
i fixed it, rewrote the code back