Solved

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

Posted on 2007-11-29
4
909 Views
Last Modified: 2010-04-21
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
Comment
Question by:joerinnis
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:netsmithcentral
Comment Utility
Check this
Function CommaCount( str )

	CommaCount = UBound( Split( str, "," ) )

End Function

Open in new window

0
 

Author Comment

by:joerinnis
Comment Utility
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
 
LVL 12

Accepted Solution

by:
netsmithcentral earned 125 total points
Comment Utility
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
 

Author Closing Comment

by:joerinnis
Comment Utility
Excellent, thanks for the help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

15 Experts available now in Live!

Get 1:1 Help Now