-
I'm trying to extract a string out of a line in a file. For example, in the line of a text file I have
<TITLE>string to extract here</TITLE>
In which case I need to extract the string. The string will be different lengths in different files. Anyone know how to go about this?
-
I have done this using the Split function. If posible find a way to dilimit, "<Title>", the return is a string array.
-
Try this:
Code:
Function ExtractString(sSearch As String, sBracket1 As String, sBracket2 As String) As String
Dim iBracket1 As Long, iBracket2 As Long
iBracket1 = InStr(1, UCase(sSearch), sBracket1)
iBracket2 = InStr(iBracket1, UCase(sSearch), sBracket2)
ExtractString = Mid(sSearch, iBracket1 + Len(sBracket1), iBracket2 - Len(sBracket2))
End Function
Usage:
MsgBox ExtractString(Text1, "<TITLE>", "</TITLE>")
-
Thanks. Thats worked. But it seems to work only on short HTML tags. For example, when I try something like this:
myNewFile.writeline ExtractString(strFileRead, "<TD WIDTH=""60"" ALIGN=""RIGHT""><B><U>", "</U></B></TD>")
It prints the string I'm looking for and the trailing HTML tags. Am I doing something wrong here?