Solved

How can i count the Alphabet  using vb.net

Posted on 2009-05-17
4
730 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

16 Experts available now in Live!

Get 1:1 Help Now