Post by ranilwallace on Jul 22, 2015 22:42:28 GMT 10
Hi everyone .I wanted to ask how am i able to read multiple lines from a text file. For example I want to store user settings in it like "Save history = true". How can i get that line then turn it into a string then and then split it so that i get the info after the "=" sign so i can say something like "If savehistory = false then" and soo on.
Ranil, Lauve Tech
|
|
Post by Makan on Jul 23, 2015 0:05:41 GMT 10
I know that you could do it pretty easily with if statements. What I would do for something like that is has the file open and then have it search for the code. For example, I would have the program open the config for something and put it into a textbox1, from there I would type in:
If TextBox1.Text.Contains("my.settings.something = true") Then 'True thing happens Else 'Can't find, will do if false. End If
So it would look for the text inside of your config and if it finds it, something would happen. But then I also wrote else so that it would do the other thing if it can't find the true thing. If you want to do it multiple times, just copy and paste with every command.
However: I don't think this will work with strings such as my.settings.comething = "STRING", I have heard of the Split method where you can split parts of code, but I am not too sure of how that works.
Last Edit: Jul 23, 2015 0:06:04 GMT 10 by Makan
|
|
Post by ranilwallace on Jul 23, 2015 1:24:25 GMT 10
ok thank you
Ranil, Lauve Tech
|
|
Post by efwwww on Jul 23, 2015 1:39:17 GMT 10
You can try using .SubString() to get the text after a specific number of characters. What you would need to do is find the number of characters before the "=" sign. Personally, I would leave out the spaces to make it easier to parse. But that's just me.
|
|
Post by Makan on Jul 24, 2015 1:45:49 GMT 10
Don't forget to make the thread solved There should be a button on my post if your answer was solved.
|
|
Post by Imformas on Jul 24, 2015 2:38:11 GMT 10
You could try using a StreamReader For Each string As String in New StreamReader("yourfile).ReadLine.slip("|") if string == "yoursetting" Then return true Next
Programming language'sCSharpC++CObjective-CVBProject'sSharpMediaSharpEditYoutifygithub.com/Stephen-Fox-0
|
|
Post by dar on Jul 24, 2015 21:49:09 GMT 10
Split*
|
|
Post by ranilwallace on Jul 25, 2015 21:53:51 GMT 10
maybe hmm. lemmi test it
Ranil, Lauve Tech
|
|