Solved

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

Posted on 2007-11-29
4
915 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sudden decrease in performance when updating mysql using classic asp 6 35
Insert Button on a table 16 47
Designing forms 3 45
IIS 7 and executing pages using localhost 16 26
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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/…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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