Skip to main content
Known Participant
April 7, 2011
Question

FindNoCase to find last occurance

  • April 7, 2011
  • 2 replies
  • 743 views

How would i use findnocase to find the last occurance of an element in my list?

    This topic has been closed for replies.

    2 replies

    Inspiring
    April 8, 2011

    Maybe I'm reading your post too literally, but if you are looking to find the last occurance of an element of a list, wouldn't you want to use listLast() ? If maybe what you are trying to do is to find the position of the last occurance of a specific value in the list, then look on cflib.org for one of the functions that will reverse the elements of a list, then use listFind() to find it in the reordered list, and do the math with listLen() to figure out what its original position was.

    -reed

    Inspiring
    April 7, 2011

    Well, if it was me doing it, I'd start by writing some code.  It might work... it might not... but it's a start.  Also, that way, you're at a better place to ask questions when it doesn't work, eg "I've got this code, but it doesn't work because I'm seeing [something] when I actually expected to see [this other thing]".

    That said, I would not use a loop and findNoCase() to do this.  I'd probably use java.lang.String's lastIndexOf() method.  Bearing in mind that CF strings (so, accordingly CF lists, which are just strings with one character treated as a delimiter) are just Java strings, one can use Java methods on them no problem.

    If I wanted to stick with CF, I'd use reFindNoCase().

    On the whole, if one finds one's self looping over a string to extract part of it, there's a good chance it's not the best approach.

    --

    Adam