Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 919
  • Last Modified:

How can I count the number of occurances of a comma within a string using asp

I'm looking for a function or script that will evaluate a string expression and count the number of times a comma appears using asp.  
Example:
The string value is "1,35,1,32".  
I want the function or script to evaluate the above string and return a value of 3.
Thanks
0
joerinnis
Asked:
joerinnis
  • 2
  • 2
1 Solution
 
netsmithcentralCommented:
Check this
Function CommaCount( str )
	CommaCount = UBound( Split( str, "," ) )
End Function

Open in new window

0
 
joerinnisAuthor Commented:
Thanks, I think this is exactly what I need however I do not have a lot of experience with functions and am having difficulty incorporating it into my code.
The string variable to be evaluated is being passed from another script in a form field. How do I incorporate the function into my code so it evaluates the form field.

For example the variable is:
<% request.form("ID") %>

Thanks for the help
0
 
netsmithcentralCommented:
Call the function with the parameter you want to count the commas in, it will return the count to you (e.g. CommaCount( "213123,124124,123,23123," ) = 4 )
<%
Function CommaCount( str )
        CommaCount = UBound( Split( str, "," ) )
End Function
%>
<html>
<body>
There are <%= CommaCount( Request.Form("ID") ) %> commas in the ID variable.
</body>
</html>

Open in new window

0
 
joerinnisAuthor Commented:
Excellent, thanks for the help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now