Solved

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

Posted on 2007-11-29
4
913 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
ID: 20377684
Check this
Function CommaCount( str )
	CommaCount = UBound( Split( str, "," ) )
End Function

Open in new window

0
 

Author Comment

by:joerinnis
ID: 20379786
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
ID: 20385276
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
ID: 31411801
Excellent, thanks for the help.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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