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....

Recommended Answers

All 3 Replies

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.

Regards

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.

Regards

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)

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")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.