last index of an ocurrence ???

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default last index of an ocurrence ???

    hi guys !

    is there a way to look to the last index of a character on a string, since i
    have been checking the help on coldfusion mx and i can find the refence of
    Find, and just works for searching the first ocurrence, and the last one ???

    anyone can help ?

    thx

    AcidGuy Guest

  2. Similar Questions and Discussions

    1. Settle a debate - to index or not to index?
      I have 2 tables: mysql> desc a; +---------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key |...
    2. Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
      Hey Folks,(New to .NET) This is driving me NUTZ... If anyone out there can resolve this from me I would greatly appreciate it... Line 238: Line...
    3. Index Topics and Index References
      Ok here is my problem. I Generate my Index and it keeps coming up with the original index i created. I went through all the chapters in my manual...
    4. Newb query: index.htm & index.php & the server default
      The problem I'm trying to solve is as follows: The website has two subdirectories: /ordinary and /phpstuff. Users typing hostname/ordinary get the...
    5. Create index VS Set Index Enabled - IDS 7.31
      Hi List, I am in the process of re-doing my production DB. One of the step I decide to perform was to "Set index enabled" instead of of...
  3. #2

    Default Re: last index of an ocurrence ???

    > I don't know if there is a lastIndexOf function, but you could always

    CF Strings extend Java Strings, so you can just use the lastIndexOf()
    method of java.lang.String.
    --

    Adam
    Adam Cameron Guest

  4. #3

    Default Re: last index of an ocurrence ???

    You can always use REFind with "returnsubexpressions" set to "true". What this
    does is return two arrays, one with the every position in the string that it
    found your search term, and another with the length of the match. Once you get
    that, just look at the last position. So you'd have something like:

    <cfset theString = "Cats are cool. I like cats. Cats are my friends. How many
    cats do you have?">
    <cfset theMatch = "cats">
    <cfset findResult = REFind(theMatch,theString,1,true>

    So now findResult looks something like:

    findResult.pos[1] = 1;
    findResult.pos[2] = 23;
    findResult.pos[3] = 29;
    findResult.pos[4] = 59;

    findResult.len[1] = 4;
    findResult.len[2] = 4;
    findResult.len[3] = 4;
    findResult.len[4] = 4;

    And if you wanted to know the position of the very last occurance, just go:

    <cfset lastMatchPosition = findResult.pos[Len(findResult.pos)]>

    Because Len(findResult.pos) will always return the index of the last match.

    Hope that helps!

    Cannikinn Guest

  5. #4

    Default Re: last index of an ocurrence ???

    I don't know if there is a lastIndexOf function, but you could always
    reverse the string and find the first index. Then just adjust that number to
    reflect the position from the end of the string.
    "AcidGuy" <webforumsuser@macromedia.com> wrote in message
    news:d72771$1r3$1@forums.macromedia.com...
    > hi guys !
    >
    > is there a way to look to the last index of a character on a string,
    since i
    > have been checking the help on coldfusion mx and i can find the refence of
    > Find, and just works for searching the first ocurrence, and the last one
    ???
    >
    > anyone can help ?
    >
    > thx
    >

    _jt Guest

  6. #5

    Default Re: last index of an ocurrence ???

    Good tip!

    "Adam Cameron" <adam_junk@hotmail.com> wrote in message
    news:n9qiq392pwc8$.11zbyoqil6ku2.dlg@40tude.net...
    > > I don't know if there is a lastIndexOf function, but you could always
    >
    > CF Strings extend Java Strings, so you can just use the lastIndexOf()
    > method of java.lang.String.
    > --
    >
    > Adam

    _jt Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139