Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-04
5
Medium Priority
?
226 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 500 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 1000 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 500 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

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. 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 : Open Page or Post…
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…

719 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