I need to write lotusscript code to read from a text file into a dynamic string away. Can’t find a good example of it on the net. Any suggestions?
Subject: More info needed
Do you want each line as a new element in the array?Do you want a line broken into multiple strings, each of which is a new element?
The efficient way to do each is different
Subject: array
The text file is an flat text output from a malware message. I want to imput that text file into a string array then use the “like” operator to fish out the hyperlinks from the array, then embed then into a message. In a nutshell.
Subject: Use a list
Dim row List As StringDim cnt as Long
Dim tmp as String
Open “c:\foobar.txt” for Input as #1
cnt = 0
Do until Eof(1)
cnt = cnt + 1
Line Input #1, tmp
row(Cstr(cnt)) = tmp
Loop
Close #1
Forall r in row
Calll ParseRow(r)
End ForAll
The you simply write a function to parse the links out of the text passed to the function.
Subject: What sort of data?
How you write the code depends on what data you want to read. This will dictate whether you should use the “Input function”, the “Input #” statement or the “Line Input #” statement.
Phil
Subject: array
The text file is an flat text output from a malware message. I want to input that text file into a string array then use the “like” operator to fish out the hyperlinks from the array, then embed then into a message. In a nutshell.
Subject: my code
OK this is what I have but it seems to be looping
Dim pathname As String
Dim stream As notesstream
Set stream = s.CreateStream
pathname = "c:\notes\data\Mime.txt"
If Not stream.Open(pathname, "ASCII") Then
MessageBox pathname,, "Open failed"
Exit Sub
End If
If stream.Bytes = 0 Then
MessageBox pathname,, "File has no content"
Exit Sub
End If
Dim message As NotesDocument
Dim mimefilestring As String
Dim email As NotesRichTextItem
Set message = db.createdocument
Set email = New NotesRichTextItem (message, "Body")
mimefilestring$ = stream.ReadText(STMREAD_LINE)
While (Not stream.isEOS)
If mimefilestring$ Like "<href * >" Then
Call email.appendtext(mimefilestring$)
End If
Wend
Call stream.close
Call message.send(False, "Victor_Johnson@independent.com")
End Sub
Subject: You are not reading from the stream inside the loop…
You have a call to ReadText before the While loop but not one inside the loop to get the subsequent lines. So it never reaches the end of stream hence you have an infinite loop.
Subject: thanks
Thanks for your help Wayne. I got it to work now with what you suggested. Here is one last thing I am running into. What is the best way to search for a string pattern within a string using two inputs. In other words, I want to find all instances of when string2 and string3 both together are within string1.
so I am basically looking for this patter:
a substring that contains both “href” and “>”
that’s in a string using lotusscript
Subject: I would just use a nested Instr…
You could use a regular expression, but I would just do something like this:
nPos1 = Instr(1, string1, “href”, 5)
if nPos1 > 0 then
nPos2 = Instr(nPos1, string1, “>”, 5)
if nPos2 > 0 then
bFound = True
end if
end if
Subject: Regexp in Lotusscript
I posted about one way to use regexp in Lotusscript (Windows only) earlier this year:Regular Expressions in Notes (Lotusscript) – TexasSwede
In case anyone is interested.