Skip to main content
2Charlie
Inspiring
Feb 29, 2016 8:27 PM UTC
Question

What is the best way to read value from a session variable that has comma separated values?

I'm comparing values in a session variable that are in comma separated to local JSON values. What is the best way to read the comma separated value from the session.groups variable?

    This topic is closed to new replies. Start a new post to keep the conversation going.

    9 replies

    BKBK
    Community Expert
    Community Expert
    Mar 5, 2016 2:30 PM UTC

    2Charlie wrote:

    What is the best way to read the comma separated value from the session.groups variable?

    The best way in Coldfusion to read a variable that consists of comma-separated values is to treat it as a list.

    Translate
    Carl Von Stetten
    Legend
    Mar 1, 2016 4:35 PM UTC

    Show us some sample data and what you mean by "comparing".

    Translate
    2Charlie
    2CharlieAuthor
    Inspiring
    Mar 1, 2016 5:08 PM UTC

    The session variable contains values like this:

    KB.DEVUNITS.BUSINESS-COMMUNICATION,KB.DEVUNITS.ACCOUTING-FINANCE,KB.DEVUNITS.BIOLOGY,KB.FILES.ADMIN,KB.DEVUNITS.NURSING,KB.DEVUNITS.ARMY-ROTC,KB.DEVUNITS.MANAGEMENT-MARKETING,KB.DEVUNITS.ADMISSIONS,KB.DEVTRAINING,KB.DEVUNITS.HOUSING-RESIDENCE-LIFE,KB.DEVUNITS.ARTS-AND-SCIENCE,KB.DEVUNITS.ON-CAMPKB-MBA,KB.DEVUNITS.ATHLETICS,KB.DEVUNITS.INFORMATION-SYSTEMS,KB.DEVUNITS.COLLEGE-OF-BUSINESS,KB.DEVUNITS.STUDENT-SENATE,KB.DEVUNITS.CAMPKB-LIFE,KB.DEVUNITS.POWER-OF-AND,KB.DEVUNITS.CHAASE,KB.DEVDEVELOPER,KB.DEVUNITS.NEWS,KB.CSADMIN,KB.DEVUNITS.CADE,KB.DEVUNITS.CONTINUING-ED,KB.DEVUNITS.COLLEGE-OF-EDUCATION-AND-HUMAN-SCIENCES,KB.DEVAUTHOR.ACCESS,KB.DEVUNITS.KOKB,KB.DEVUNITS.SALES-CENTER,KB.DEVUNITS.LANGUAGES,KB.CSDEVELOPER,KB.DEVUNITS.NURSING-HEALTH-SCIENCES,KB.KBREDESIGN,KB.DEVUNITS.SPECIAL-EDUCATION,KB.DEVUNITS.ON-CAMPKB-DINING,KB.DEVUNITS.RECREATION-INTRAMURALS,KB.DEVUNITS.OFFICE-OF-INTERDISCIPLINARY-PROGRAMS,KB.DEVUNITS.PSYCH,KB.DEVADMIN,KB.DEVUNITS.ACADEMICS

    In the loop of each of the JSON data, I want to compare if the data in the json matches one or more of the data in the session variable.

    Translate
    Carl Von Stetten
    Legend
    Mar 1, 2016 5:16 PM UTC

    How about a sample of the JSON data?

    In general, comma-separated data stored in ColdFusion variables are treated as lists, so you can use any of the LISTxxx() functions on them.  In your case, you can probably use ListFind() or ListFindNoCase() (the latter if the JSON data isn't in upper case like the sample data you showed above.  Also, you can turn a list into an array using ListToArray(), then use Arrayxxx() functions to match your values.  Arrays usually perform a bit better than lists if the lists are fairly long.

    Translate