Solved

How can i count the Alphabet  using vb.net

Posted on 2009-05-17
4
729 Views
Last Modified: 2012-06-27
example:

dim xvar as string
xvar="abc0001"
In this variable 'xvar' how can i count the number of alphbet
 
0
Comment
Question by:mseit
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24409351
What do you mean with the coutn of alphabet ?
What is the desired output for given example ?
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 24409413
try this

In intLoopLetter variable you get the number of alphabets
       Dim xvar As String

        xvar = "abc000123a"
 

        Dim current As Integer

        Dim intLoopStrText, intLoopLetter As Integer

        xvar = xvar.ToUpper

        intLoopStrText = 0

        intLoopLetter = 0

        While (intLoopStrText < xvar.Length)

            current = Asc(xvar.Substring(intLoopStrText, 1))

            If current >= 65 And current <= 90 Then

                intLoopLetter = intLoopLetter + 1

            End If

            intLoopStrText += 1

        End While

Open in new window

0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 24409427
mseit, are you trying to count the number of alphabets in the given string?
If so you can try:

Dim count As Integer = 0
For Each c As Char in xvar
    If Char.IsLetter(c) Then count += 1
Next

You get the result in variable count
0
 

Author Closing Comment

by:mseit
ID: 31582492
Excellent Solution
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

20 Experts available now in Live!

Get 1:1 Help Now