Print Page | Close Window

How many Char(10) in var

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4364
Printed Date: 30 March 2026 at 6:37am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: How many Char(10) in var
Posted By: fernan82
Subject: How many Char(10) in var
Date Posted: 19 July 2003 at 6:06pm
How can I get how many of a certain character there is on a variable......... ex. if i want to know how many A theres is on a var is there a simple function that will return that value..?

Thanks in advance,

-------------
FeRnAN
http://www.danasoft.com/">



Replies:
Posted By: sprychun
Date Posted: 19 July 2003 at 6:28pm

In VBScript you can do this:

Dim FindChr
Dim MyString
Dim CurChr
Dim Chrs
Dim A

FindChr = "B"
MyString = "ABCABCABCA"

Do

A = A + 1
CurChr = Mid(MyString, A, 1)
If CurChr = FindChr Then Chrs = Chrs + 1

Loop until A = len(MyString)

call MsgBox(Chrs)



Posted By: sprychun
Date Posted: 19 July 2003 at 6:30pm
If you need an explaination on this code please reply. Otherwise I hope it works for you.


Posted By: Mart
Date Posted: 20 July 2003 at 10:17am

Function countchar(text, letter)

Dim length, currentletter

length = len(text)

For i = 1 to length

currentletter = mid(text, i, 1)

if currentletter = letter Then

countchar = countchar + 1

End if

Next

End Function

response.write countchar(variable, "A")




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net