Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > ColdFusion

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-29-2010, 06:20 PM   PM User | #1
Jt107
New Coder

 
Join Date: Nov 2002
Posts: 29
Thanks: 1
Thanked 0 Times in 0 Posts
Jt107 is an unknown quantity at this point
count "(" in string

I need to do an input text validation which include opening parenthesis and closing parenthesis, what I need to validate is the opening parenthesis match with closing parenthesis. Here is a sample of the entry text:

thisis(test(of(matching(parenthesis)and)if)working

which one closing parenthesis is missing. I would like to warn the user to correct it before submit.

When I use ListValueCount(form.myValue,"(")> gives me 0 accourance.
Not sure how could I count the "(" and ")" to compare. Please advice.

Thanks,
JT
Jt107 is offline   Reply With Quote
Old 11-29-2010, 08:19 PM   PM User | #2
Jt107
New Coder

 
Join Date: Nov 2002
Posts: 29
Thanks: 1
Thanked 0 Times in 0 Posts
Jt107 is an unknown quantity at this point
use the following function to solved the problem:
<cffunction name="countOccurrences" access="public" returntype="numeric" required="true">
<cfargument name="string" type="string" required="True" />
<cfargument name="subString" type="string" required="True" />

<cfset VAR position = findNoCase(arguments.substring,arguments.string,1) />
<cfset VAR count = 0 />

<cfif len(trim(arguments.substring))>
<cfloop condition="position NEQ 0">
<cfset count = count + 1 />
<cfset position = findNoCase(arguments.substring,arguments.string, position + len(trim(arguments.substring))) />
</cfloop>
<cfelse>
<cfreturn 0 />
</cfif>

<cfreturn count />
</cffunction>
Jt107 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:13 PM.


Advertisement
Log in to turn off these ads.