Solved

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

Posted on 2009-04-04
5
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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…

623 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