Solved

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

Posted on 2007-11-29
4
914 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide row when retrieving data from database 6 69
SQL to update characters in table column 6 147
Passing Parameter to Stored Procedure 4 27
Adjust an existing ASP Query 45 16
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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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