|
-
Oct 4th, 2006, 12:05 PM
#1
Thread Starter
Addicted Member
Parse (find string in) text file?
Hi,
I'm wondering what is faster way to find string in another string(filled from 350kb text file) using string.IndexOf method or using regular expression.
thanks j
-
Oct 4th, 2006, 01:39 PM
#2
Fanatic Member
Re: Parse (find string in) text file?
I don't know if its faster, but you can try this:
VB Code:
Private Function FindIndex(data as String, search as String) as Int32
Dim found as Boolean = False
Dim i as Int32
For i = 0 to data.Length - 1
If data.SubString(i, search.Length) = search
found = True
Exit For
End If
Next
If found Then
Return i
End If
Return -1
End Function
-
Oct 4th, 2006, 02:45 PM
#3
Re: Parse (find string in) text file?
using IndexOf is faster that using RegEx because the RegEx compiles the pattern before searching
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 4th, 2006, 03:43 PM
#4
Re: Parse (find string in) text file?
Regex is handy to search for patterns of text, not one particular string that you know will come up. Like searching for a phone number. You can use Regex to match on a phone number pattern and have it return all phone numbers in the file that matches the pattern, instead of coding the phone number that you want to search for and using .IndexOf or some other method. If its not a pattern or special kind of string you want to search for, then Regex shouldn't be necessary.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|