Hello Friends,

I want to calculate the instance of * in the text file....

but I am not able to do it....

can anyone tell me which file funtion to use for it...

I first tried to read the file --- its just one line file

then see if the character '*' exists in the file...

I am done till here...i dont to know to proceed further....

6 Years
Discussion Span
Last Post by Mitja Bonca

i cant get you pooja , what do you mean by instance , well if you just want to know is * is in text file ? please check this attachment.


Not able to open the file...i wanted to know how many times * exists in the file .... nyways I got the answer....

Dim abc As String = "abc*def*sjfsd*xdvx*"
                        Dim pattern As String = "\*"
                        Dim expr As New System.Text.RegularExpressions.Regex(pattern)
                        Dim m As System.Text.RegularExpressions.MatchCollection
                        m = expr.Matches(abc)
                        Debug.Print("m count: " + m.Count.ToString)

Edited by poojavb: n/a


Try do use StreamReader class to read the file line by line, and count repetitions of char:

Dim counter As Integer = 0
Using sr As New StreamReader("filePath")
	Dim line As String
	Dim data As String() = Nothing
	While (InlineAssignHelper(line, sr.ReadLine())) IsNot Nothing
		If line.Contains("*"C) Then
			data = line.Split(New Char() {"*"C}, StringSplitOptions.None)
			counter += data.Length - 1
		End If
	End While
End Using
MessageBox.Show("char * was counted: " & counter & " times")
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.