|
-
July 17th, 2003, 11:13 AM
#1
Identification of characters in a text file
Hi, I was just wondering, say i wanted read a file but i only wanted to read 1 word or line from it. for example
whfduweihrfweihrfweihfsdhfsdhfsdjkfhsdkjhfkjwrew
the word in red is the word that i wanted to be printed to the text box on screen, is this possible?... if so dont suppose anyone could yell me how to do it?...
Thanks Nick
-
July 17th, 2003, 12:34 PM
#2
This should get you going...
Private Sub Command1_Click()
Dim fs, f, ts
Dim pos
Dim result As String
Dim MyString As String
Dim s As String
MyString = "weih"
'Ensure MS scripting runtime is selected in References
Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.GetFile("c:\test1.txt")
Set ts = f.OpenAsTextStream(ForReading, 0)
s = ts.ReadAll
pos = InStr(1, s, MyString, 1)
result = Mid$(s, pos, Len(MyString))
MsgBox result
Set ts = Nothing
Set f = Nothing
Set fs = Nothing
End Sub
-
July 17th, 2003, 12:43 PM
#3
if you want to check for words you can do this , once you ave the string at hand :
Code:
Private Sub Command1_Click()
Dim s As String
s = "whfduweihrfweihrfweihfsdhfsdhfsdjkfhsdkjhfkjwrew"
If InStr(s, "weih") Then
MsgBox "weih" ' /// weih is in the text
End If
MsgBox UBound(Split(s, "weih")) ' /// the amount of times weih is in there ( eg: 3 )
End Sub
string Signature = Censored; 
-
July 20th, 2003, 10:24 AM
#4
Okay thanks guys that helped me alot.
now i need to spice it up
say i wanted to select character 9 then 16 then 19 from a sentance and then put them together in a text box is this possible. for example
whfduweiwprnsektinorkfjrnwqlkrjewkhfuj
the letters in red are the letters i want to be selected.
w = 9
t = 16
o = 19
If anyone could help me that would be great. Thank you very much
Nick
-
July 21st, 2003, 06:47 AM
#5
You can use the Mid$() function to copy from the string..
Code:
Private Function CollectChar(sString As String, ByVal sChars as String) As String
Dim i&
Dim sResult$
sResult = ""
For i = 1 to Len(sString)
If Instr(sChars, Mid$(sString, i, 1)) <> 0 Then
sResult = sResult & Mid$(sString, i, 1)
End If
Next i
CollectChar = sResult
End Function
Busy 
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
|