Solved

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

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
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 create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now