Solved

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

Posted on 2009-04-04
5
217 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

729 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