• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

should I be using REFindNocase in this case?

New Here ,
May 04, 2017 May 04, 2017

Copy link to clipboard

Copied

Hi,

I need help on the function REFindNocase. The project is old and still using CF9 so there is a limitation on what can be use.

Each student has a different BookSelectList. Example: it can be NULL (which allows them to see all books), or 1 (which allows them to see only Book A) or 1,2,3 (which allows them to see only Book A, B, C)

We have the below:

<cfif REFindNocase("(1|2|3|4|5|6)",#Selection.BookSelectList#)>

    <cfinclude template="showbooks.cfm">

</cfif>

Which works fine until we hit book 10, since 10 consist of "1". REFindNocase will return 1 and display something they are not meant to see.

What can I do to avoid that? Can REFindNOcase compare Numbers instead of String? If so, how it can be done?

Thanks in advance!

Views

941

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

LEGEND , May 08, 2017 May 08, 2017

For the sake of discussion, let's say that Selection.BookSelectList is returned as "1,3,7,10,11" for one student.  So now you have a list of five values.

If you iterate the list and set the REFind() (you don't need NoCase unless you're comparing text) to search each iteration (individual) value from start of 'string' to end...

<cfloop list="#Selection.BookSelectList#" index="ndx"> <!--- ndx will be '1' on first iteration; '3' on second iteration, etc. --->

  <cfif ReFind("^(1|2|3|4|5|6)$",trim(ndx.

...

Votes

Translate

Translate
LEGEND ,
May 04, 2017 May 04, 2017

Copy link to clipboard

Copied

I haven't tested this, but I think that if you set it up so that the string compare is for beginning (^) to end ($) then the REFindNoCase() will check the values against the whole argument.

<cfif REFindNoCase("^(1|2|3)$",Selection.BookSelectList)>

<!--- Since Selection.BookSelectList is not within quotes, using the hashmarks is not only unnecessary, but will also slow things down.--->

This will compare the whole Selection.BookSelectList against the RegEx instead of searching globally for any instance.

HTH,

^_^

Votes

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
LEGEND ,
May 04, 2017 May 04, 2017

Copy link to clipboard

Copied

I just re-read your post, and realized that my suggestion won't work if an actual list is presented.. SO.. what you can do, then, is iterate through the list looking for the RegEx mask and if found set a variable to true, then proceed from there.

HTH,

^_^

Votes

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
Advocate ,
May 04, 2017 May 04, 2017

Copy link to clipboard

Copied

Maybe:

<cfset variables.showBooks = len(Selection.BookSelectList) EQ 0 />

<cfloop index="variables.v" list="1,2,3,4,5,6,10">

    <cfset variables.showBooks = variables.showBooks OR listFind(Selection.BookSelectList,variables.v) NEQ 0 />

</cfloop>

<cfif variables.showBooks>

    <cfinclude template="showbooks.cfm" />

</cfif>

A regular expression search can be used but for this example I would say it is more trouble than it's worth. Also, the initial setting of showBooks checks for the NULL (empty string) value that your regular expression example code was missing.

Votes

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 ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

The problem is I will have no idea what is being return.

Selection.BookSelectList could be anything depends on the student. Some students will have just 1 book while the other has 5. ie.

Student 1's Selection.BookSelectList could be (6, 10)

Student 2's Selection.BookSelectList could be (18)

Student 3's Selection.BookSelectList could be (1, 3, 5)

The problem with REFindNoCase() is that if anyone that has book 10 then book 1 will show as well because the function is reading it as a string, and 10 consist of the string 1 in it.

Votes

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
LEGEND ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

For the sake of discussion, let's say that Selection.BookSelectList is returned as "1,3,7,10,11" for one student.  So now you have a list of five values.

If you iterate the list and set the REFind() (you don't need NoCase unless you're comparing text) to search each iteration (individual) value from start of 'string' to end...

<cfloop list="#Selection.BookSelectList#" index="ndx"> <!--- ndx will be '1' on first iteration; '3' on second iteration, etc. --->

  <cfif ReFind("^(1|2|3|4|5|6)$",trim(ndx.toString()))><!--- RegEx is searching full string compared value, not just anywhere or global --->

  ... <!--- Will return TRUE for 1, but not 10 --->

  </cfif>

</cfloop>

HTH,

^_^

Votes

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 ,
May 09, 2017 May 09, 2017

Copy link to clipboard

Copied

Oh man, this works perfectly!!!!! THanks so much for your help! Greatly greatly appreciated.

KT

Votes

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
LEGEND ,
May 09, 2017 May 09, 2017

Copy link to clipboard

Copied

LATEST

Glad to hear that you got it working.  And thank you for marking my answer correct.  I do appreciate it.

V/r,

^_^

Votes

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
Community Expert ,
May 05, 2017 May 05, 2017

Copy link to clipboard

Copied

Try

<!--- To match free digit 1-6 --->

<cfif REFindNocase("^[1-6]$",Selection.BookSelectList)>

<!--- To match digit 1-6 among other (non digit) characters--->

<cfif REFindNocase("^[1-6]$|^[1-6][\D]|[\D][1-6]$|[\D][1-6][\D]",Selection.BookSelectList)>

Votes

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 ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

I have an error when I tried you way:

Malformed regular expression "^[9-11]$".

Reason: Invalid [] range in expression..

My Selection.BookSelectList returns 6, 10. Is it because it's not returning anything in 9-11 so it gives me an error?

Votes

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
Community Expert ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

[9-11]

You cannot do that. The [] match is for single digits, which I had assumed was what you wanted. For 2 digits, use the same method, but then with [][].

Votes

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
Resources
Documentation