ListFind but only first instance of letter at START of item

New Here ,
Apr 28, 2019 Apr 28, 2019

Copy link to clipboard

Copied

I am familiar with several list functions in CF but I can't seem to figure out how to do this thing:

I have a long list (from a query in coldfusion) of names, e.g. "john" or "silverfox" or "7" (all "user aliases").  say, query.alias

I have to put this out on a page and it's way too many for sanity.

I want to break it up by the first letter of the name. Like:

*: (list from the point before names begin with letters, like numbers and special chars)

A: (list from the point where names begin with A)

B: (list from the point where names begin with B)

C: (list from the point where names begin with C)

But listfind just finds the first "a" (and none of are just 'a' as a name), and listcontains just finds the first name that contains an A anywhere.

How can I find the location in the list of where a value BEGINS WITH a certain string ("a"), so I can make a var of that value, and then loop the query out with a rowcount and 'start/stop' it at the appropriate places? (I guess that's how it would be done, seems logical.)

I would so appreciate any advice. I've been searching all day and haven't yet found this specific answer.

PS I want to add that I'm having serious shared-server timeout problems so I'm trying to minimize database calls, hence not wanting to loop 27 queries instead...

Best,

PJ

Views

148

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Apr 29, 2019 Apr 29, 2019
The ArrayEach function will let you go through an array and run whatever function you want against each array member. So you could (a) sort the array, then (b) write a function that finds the first character in each value and writes that information into another array for each unique character, or whatever. Or you could use the callback function in ArraySort to both sort entries and to copy them into separate arrays. I'm sure there are several ways to solve this problem. You won't be able to do ...

Likes

Translate

Translate
New Here ,
Apr 29, 2019 Apr 29, 2019

Copy link to clipboard

Copied

I wonder if the lack of response means "this is not possible in coldfusion." 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 29, 2019 Apr 29, 2019

Copy link to clipboard

Copied

Any kind of string or sort operation you want to do, you can do in ColdFusion. So, I think the lack of response means "no one wants to write code for someone else". My recommendation would be to put all the list items in an array, and use all the array functions you need to do what you want. But like most everyone else, I'm too lazy to work through the code myself.

Dave Watts, Eidolon LLC

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2019 Apr 29, 2019

Copy link to clipboard

Copied

The problem is I cannot find an array function that will find something based on the first letter of the individual item. I can only find functions that find either whole items, or something 'in' an item. But that would give me 400 names that have the letter "A" in them, not the first item that begins with A. So I don't want code... I just want to know what function or approach might work to accomplish that.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 29, 2019 Apr 29, 2019

Copy link to clipboard

Copied

The ArrayEach function will let you go through an array and run whatever function you want against each array member. So you could (a) sort the array, then (b) write a function that finds the first character in each value and writes that information into another array for each unique character, or whatever. Or you could use the callback function in ArraySort to both sort entries and to copy them into separate arrays. I'm sure there are several ways to solve this problem. You won't be able to do this with a single built-in function, you'll have to write some additional code to get where you want to go.

Dave Watts, Eidolon LLC

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2019 Apr 29, 2019

Copy link to clipboard

Copied

LATEST

Got it. I haven't worked with ArrayEach, that sounds like the ticket, maybe with a regex. Thanks for your help Dave.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines