|
-
May 12th, 2001, 11:12 PM
#1
Thread Starter
Lively Member
Finding a string in text
The way I've been finding a string in text is a slow way.
Here's how I would:
For I = 1 to Len(rtbFile.txt)
If Mid(rtbFile.txt, I, 9) = "Something" then
'Found Text
End if
Next I
I know this a slower way than normal. How would I find a string faster than using this method?
Thank you for any help
-Justin Gomes
[email protected]
-
May 13th, 2001, 12:03 AM
#2
Code:
Dim FileName As String
FileName = "rtbFile.txt"
Dim strTemp As String
Open FileName For Input As #1
strTemp = Input(LOF(1),1)
Close #1
If InStr(1,strTemp,"Something") <> 0 Then
MsgBox "String Found!"
End If
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 13th, 2001, 12:06 AM
#3
Use the Like operator.
Code:
If rtbFile.txt Like "*Something*" Then Msgbox "Something found!"
-
May 13th, 2001, 03:05 AM
#4
Junior Member
'match case
If InStr(1,strTemp,"Something",vbBinaryCompare) <> 0 Then
MsgBox "String Found!"
End If
'no match case
If InStr(1,strTemp,"Something",vbTextCompare) <> 0 Then
MsgBox "String Found!"
End If
for a good tool for programmers.
please visit: http://www.iCodeRepository.com
-
May 13th, 2001, 07:18 PM
#5
Thread Starter
Lively Member
I'm sorry
I am sorry I wasn't detailed enough.
After finding the string I need to know where the string is inside the file.
For example, the len of the string location
-
May 13th, 2001, 07:41 PM
#6
Code:
Dim iPos As Integer
Dim FileName As String
FileName = "rtbFile.txt"
Dim strTemp As String
Open FileName For Input As #1
strTemp = Input(LOF(1),1)
Close #1
iPos = InStr(1,strTemp,"Something")
If iPos <> 0 Then Msgbox "Something found at position: " & iPos
-
May 13th, 2001, 07:54 PM
#7
_______
<?>
Code:
'open a file and find the first occurance of a string and return the
'occurance and the remainder of the file
'remove option compare text if you want the seach to be case aware
Option Explicit
Option Compare Text
'contents of file
'I was drinking tea in the beverage room of the house
Private Sub Command1_Click()
Dim sfile As String, intNum As Integer, myString As String
intNum = FreeFile
sfile = "C:\my Documents\myfile.txt"
Open sfile For Input As intNum
myString = StrConv(InputB(LOF(intNum), intNum), vbUnicode)
Close intNum
Dim myFind As String, myLen As String, iCount As Integer
Dim mySearch As String
mySearch = "the"
For iCount = 1 To Len(myString)
myLen = InStr(1, myString, mySearch)
Next
'the balance of the file including "the first" [the]
'in this case [the beverage room of the house
myString = Right(myString, Len(myString) - (CInt(myLen) - 1))
MsgBox myString 'result of search
End Sub
[/code]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
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
|