need help to communicate via serial or parallel port

how can i find that home many times a particular letter in a string occured, e.g 'a' in 'Nauman'..the answer should be "2".

Comments

  • : how can i find that home many times a particular letter in a string occured, e.g 'a' in 'Nauman'..the answer should be "2".
    :
    :
    Try the following function for Vb.net:

    Private Function CountCharacters(ByVal target As String, ByVal character As String) As Double
    Dim counter As Double
    Dim index As Integer
    For index = 0 To target.Length - 1
    If target.Chars(index) = character Then
    counter += 1
    End If
    Next
    Return counter
    End Function


    Use the function like this:

    numberOfCharactersInString = CountCharacters(str,chr)


    Put the function in the code window between Public Class Form1 and
    End Class - but not inside another procedure.
    The arguments passed are:
    str = string that has characters that you want to count.(IE Nauman)
    chr = the character thatyou want to count. (a)
    Jabax

  • Or simpilar than this is InStr(String, Chr) Where String is the String you are searching and chr is what you are trying to find for example:

    Str1 = "Nauman"
    Intg = InStr(Str1, "a")

    Intg will then = 2

    : : how can i find that home many times a particular letter in a string occured, e.g 'a' in 'Nauman'..the answer should be "2".
    : :
    : :
    : Try the following function for Vb.net:
    :
    : Private Function CountCharacters(ByVal target As String, ByVal character As String) As Double
    : Dim counter As Double
    : Dim index As Integer
    : For index = 0 To target.Length - 1
    : If target.Chars(index) = character Then
    : counter += 1
    : End If
    : Next
    : Return counter
    : End Function
    :
    :
    : Use the function like this:
    :
    : numberOfCharactersInString = CountCharacters(str,chr)
    :
    :
    : Put the function in the code window between Public Class Form1 and
    : End Class - but not inside another procedure.
    : The arguments passed are:
    : str = string that has characters that you want to count.(IE Nauman)
    : chr = the character thatyou want to count. (a)
    : Jabax
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories