![]() |
|
[C#] C# Reading from txt file line by line - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] C# Reading from txt file line by line (/showthread.php?tid=6029760) Pages: Pages
1
2
|
C# Reading from txt file line by line - Formula 1 - Dec 2, 2019 Hello, can someone tell me how can i read from txt file (which is on directlink website) line by line? I have on the txt file some list of codes for example: XXXX-XXXX-XXXX-XXXX YYYY-YYYY-YYYY-YYYY If one of these codes is exist, do something RE: C# Reading from txt file line by line - MavenGradle - Dec 2, 2019 Since the data you're after is located online (if I understand correctly), you should consider using a WebClient or HttpWebRequest to retrieve said information. https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.net.httpwebrequest?view=netframework-4.8 After which you can split the content into multiple parts (which I would not recommend due to there being an overhead there that can be avoided) or if you're reading it as a stream, you can simply read the stream line by line: https://docs.microsoft.com/en-us/dotnet/api/system.io.streamreader?view=netframework-4.8 Obviously, it would be recommended to perform these operations asynchronously as to not block the user interface, if there's a need for that. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/ Also, if this is an attempt at protecting your application from cracking, this is not an appropriate way to handle this. RE: C# Reading from txt file line by line - Formula 1 - Dec 2, 2019 Thanks for your reply, I tried this already but its not working good. it works only for the first line, if the correct code was the second line it doesnt recognize it. RE: C# Reading from txt file line by line - MavenGradle - Dec 2, 2019 It would be helpful if you posted your code so that we could take a look at it. RE: C# Reading from txt file line by line - Formula 1 - Dec 2, 2019 Code private void button1_Click(object sender, EventArgs e)RE: C# Reading from txt file line by line - MavenGradle - Dec 2, 2019 (Dec 2, 2019 02:14 PM)uberhacker Wrote: You're reading the content of the stream to the end and comparing the entire result to the content of your textbox which is not something you want since this file you're reading from the WebClient Stream contains multiple lines and you need to have only a single hit and not having the entire content match. Instead, try reading the stream line by line and comparing the results: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-read-a-text-file-one-line-at-a-time Might I also suggest that you implement proper variable and method naming and implement error handling in case your application fails to retrieve said data or read the stream: https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient.openread?view=netframework-4.8#System_Net_WebClient_OpenRead_System_String_ https://docs.microsoft.com/en-us/dotnet/api/system.io.streamreader.readline?view=netframework-4.8 Good luck! RE: C# Reading from txt file line by line - Formula 1 - Dec 2, 2019 pfff getting an error. any help boys? RE: C# Reading from txt file line by line - MavenGradle - Dec 2, 2019 (Dec 2, 2019 05:49 PM)uberhacker Wrote: pfff getting an _error_. Sure, what's the error you're getting at the moment or is it still the same one? RE: C# Reading from txt file line by line - Accord - Dec 3, 2019 I do it like this, Code for each line in content.split(newline, stringsplitoption.none)do not copy, i just write this in mobile. RE: C# Reading from txt file line by line - N1nj4Styl3 - Dec 3, 2019 You need to setup a loop which would try the line(i) of textbox2.text against the line(j) in the list you took from the web. for i=1:size(textbox2.text) for j=1:size(OnlineList) if TextBox2.Text(i) == OnlineList(i) % DO something end end The above code is in MatLab code, I am just giving you the idea / concept how to handle it. RE: C# Reading from txt file line by line - 0xDEAD10CC - Dec 3, 2019 (Dec 3, 2019 03:29 AM)Dionysus. Wrote: I do it like this, There is absolutely no point in reading all of the data to split it up after and read line by line, if you can read the stream line by line... (Dec 3, 2019 02:48 PM)N1nj4Styl3 Wrote: You need to setup a loop which would try the line(i) of textbox2.text against the line(j) in the list you took from the web. You misunderstood the problem described in this thread and provided a completely unhelpful code sample. What you posted describes the psuedocode for a trivial part of the finished solution when OP hasn't even gotten that far. There would be better functions to call anyways opposed to this if he had a reference to the collection to check and read lines from the stream (since they could be done at the same time). Psuedocode: Code stream = httpresponse@OP - Post any errors or code changes you make so we can follow along faster. All you had to do in this case if you insist on using a WebClient over the modern HttpClient, was read the StreamReader stream with the ReadLine() method until EOF. (The function will return null in that case.) RE: C# Reading from txt file line by line - Accord - Dec 4, 2019 (Dec 3, 2019 03:29 PM)0xDEAD10CC Wrote: There is absolutely no point in reading all of the data to split it up after and read line by line, if you can read the stream line by line...Thank you, i will now used this instead of my previous post. this really help me. RE: C# Reading from txt file line by line - gigajew - Dec 4, 2019 I would probably do something like this just for a quick program RE: C# Reading from txt file line by line - ehJoe - Dec 5, 2019 (Dec 2, 2019 02:14 PM)uberhacker Wrote: Not sure if you still need this, but pretty basic shi lol.. So many better ways you can do HWID authentication, but you can test this code by copying those numbers in the raw pastebin. Assuming this is what you wanted. ❓ RE: C# Reading from txt file line by line - MavenGradle - Dec 5, 2019 (Dec 5, 2019 12:53 AM)ehJoe Wrote: Not sure if you still need this, but pretty basic shi lol.. So many better ways you can do HWID authentication, but you can test this code by copying those numbers in the raw pastebin. Assuming this is what you wanted. ❓ For pretty basic shit, I wonder why you're using string.Contains to check the entire content of the file.. You're opening yourself up to a serious flaw and it's a serious overhead that can be done better, which has already been explained multiple times on this thread now. |