Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2002
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  • #2
    New Coder
    Join Date
    Nov 2002
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •