Solved

How do I parse to see if the word copay is in a variables content

Posted on 2009-04-04
5
201 Views
Last Modified: 2013-12-24
I am doing a database query and pulling the variable "copay" whis is text that describes the benefits of the copay benefit for an insurance plan.

So copay may = "Not Covered" or "$35 copay after deductible" etc.

What i want to do is set a variable based on if the variable "copay" contains the word copay in it.

<cfif copay contains "copay" word> (I have no idea)
<cfset iscopay = 1> <cfelse>cfset iscopay = 0>
</cfif>
0
Comment
Question by:LeadCo
5 Comments
 
LVL 16

Assisted Solution

by:duncancumming
duncancumming earned 125 total points
ID: 24068322
<cfif FindNoCase(copay, "copay")>
<cfset iscopay = 1>
<cfelse>
<cfset iscopay = 0>
</cfif>
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24068359
if you need the exact word and NOT any words that contain it, you better use REFindNoCase():

something like this:
<cfset iscopay = REFindNoCase(copay, "\Bcopay\B")>

copay will be 0 if not found or a number representing position of work 'copay' in the string if found
(\B is a regex word boundary)

Azadi
0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 250 total points
ID: 24068375
of course, that should be:

<cfset iscopay = REFindNoCase("\bcopay\b", copay)>

and not the nonsense i posted before... sorry....

Azadi
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 125 total points
ID: 24068809
You were actually very close, just remove the word "word" from the example in your original post..

<cfif myQuery.copay contains "copay">
   <cfset iscopay = 1>
<cfelse>
   <cfset iscopay = 0>
</cfif>

I also like to do this at the database level sometimes... let the database do the work, it's very efficient.
In the select statement...

select copay
        , case when charindex('copay',copay) > 0 then 1  else 0 end as  isCopay
from ....

Now the variable is in the query    myQuery.isCopay  

0
 

Author Closing Comment

by:LeadCo
ID: 31566618
Thanks Guys wish I could all of you 500 points. They are all correct.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question