R4PM0NK3Y Posted December 5, 2003 Posted December 5, 2003 Hi, I need to do this: First, open a text file. Read the file until it finds the phrase "test". Once found, it needs to read the text to the right of it into a string variable, until the character "<" is reached. How could I do this? Any help is greatly appreciated! Quote
Mehyar Posted December 5, 2003 Posted December 5, 2003 'declare a stream reader giving it the file name Dim FileReader As New StreamReader("PathOfTheFile") Dim FileContent As String = FileReader.ReadToEnd() 'reads the whole file into a string Dim i As Integer = FileContent.IndexOf("test") If i <> -1 Then 'the file contains the word test 'declare a string to hold the text from test to < 'take a part of the string from where test is found + 4 (length of test) Dim Result As String = FileContent.Substring(i + 4) 'now find where < is found in this string i = Result.IndexOf("<"c) If i <> -1 Then 'the result string contains < 'take the string from the beginning till the last character (just before the <) Result = Result.Substring(0, i - 1) 'now result contains the string you want End If End If Hope this helps, Quote Dream as if you'll live forever, live as if you'll die today
R4PM0NK3Y Posted December 5, 2003 Author Posted December 5, 2003 Thanks a ton, this should work! :D Quote
R4PM0NK3Y Posted December 6, 2003 Author Posted December 6, 2003 That DID work (thanks a ton), but I made some modifications and have one more question. In this line: i = result.IndexOf("<"c) What does the "c" after "<" do? I need to change "<" to a variable name, and it seems the c is of importance, and I cannot have a variable name and the c in there. Example: i = result.IndexOf(varc) Assume the variable used is "var". What needs to be done? Thanks again. Quote
Administrators PlausiblyDamp Posted December 6, 2003 Administrators Posted December 6, 2003 In "<"c , the c simple tells the compiler to treat "<" as a character rather than a string. If you are using a variable then it isn't needed. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.