How to search for part of a string in a variable

liunx

Guest
Basically I have a long variable and I want to search that variable for a particular string.

To clarify, say I have a string "abcdefg" and I want to see if "cde" is within that string, how would I go about that, or where would I begin.

thank youI got it, tell me if there's something wrong with it though, but it works

check = CStr(sr.ReadLine)
If (check.IndexOf(condition) >= 0) Then
count = count + 1
End IfThat is correct but i must ask
I have to assume that sr is a StreamReader. But what stream is it reading ??? MemoryStream or FileStream what?

Next i would have to ask is why are you using Cstr on a function that already returns a string?When I first started working on the program, it was throwing an error if I wouldn't covert to a string. You were right though, I don't need it.

Here is my whole sub.

Dim fsIn As FileStream = New FileStream("C:\ex050728.txt", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim sr As StreamReader = New StreamReader(fsIn)
Dim check As String
Dim condition As String
Dim count As Integer
count = 0
condition = "http://www.getdebtfree.com"
While sr.Peek > -1
check = sr.ReadLine
If (check.IndexOf(condition) >= 0) Then
count = count + 1
End If
End While
TextBox1.Text = CStr(count)
sr.Close()

The only thing that I'm trying to accomplish is to count the number of times a particular url is found in a log file. I'm going to be writing a more intense log reporting program, but for a client I just need a count for now. I'm learning :)You should be using IndexOfAny function and continuing to search the string for any more occurances instead of just ending the search once you find it.
int pos = 0;
while(sr.Peek > -1){
pos = str.IndexOfAny(condition,pos);
if(pos >= 0)
count = count + 1

while(pos >= 0)
{
pos = str.IndexOfAny(condition,pos);

if(pos >= 0)
count = count + 1

};
};

I think that might correct it.thanks, that is great stuff to know. I can see how that would be a factor in just about anything else, but the strings that I'm search will have only one occurance of what I'm looking for. It does work, and I've now added to the code to go through a log folder, and search the logs for what I'm looking for. The only that I'm stuck on now is I need to be able to get the amount of days for any given month, but I made a new post for that.what type of logs are you looking at???
W3C IIS Logs???You should use odbcyou should not use ODBC as it doesn;t allow for all fields.
If you used LogParser 2.0 from MS IIS Resource Kit you would could import it in like a record set and send an SQL like statement to it to find what you are looking forSo by a log parser, are you saying that it would take my W3C log files and import them into the database? Is there anyway to have the logs get stored into a database directly so that I wouldn't have to worry about importing them, I could just write a program to fetch the data in real time?it could fetch in real time but it would not suggest that on larger sites.I see what you're saying. The site that i'm working on now is a smaller site.
 
Back
Top