![]() |
|
[.NET] Find string in textbox and move that line & 5 lines below to other textbox - 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: [.NET] Find string in textbox and move that line & 5 lines below to other textbox (/showthread.php?tid=4195286) |
Find string in textbox and move that line & 5 lines below to other textbox - ShadyShadow - Apr 26, 2014 Just like the title says, I'm working on a program that filters out certain keywords from a textbox, i got that working without any problems but my next step is that it not only moves the keyword to another textbox but also the 5 next coming lines beneath it. The keyword can appear more than 1 time in the textbox so it must be looped till the whole textbox is read. Does anyone knows how i can do this? EXAMPLE: Textbox contains: PHP Code So what i want to filter is only this: Name Lastname Phone Address ZipCode * - Moen - Apr 26, 2014 Code do untill (keyword is gone)Well you can post what you have coded and it is possible to help you from there. * - ShadyShadow - Apr 26, 2014 (Apr 26, 2014 03:28 PM)The Moen Wrote: this is what i got to find it: PHP Code * - 0xDEAD10CC - Apr 26, 2014 Are you trying to find the lines from the TextBox then or from the file directly? Using the file would be better. Find the line that you want to start at, then increment a count for how many lines you want to retrieve. When the count extends the limit, stop collecting the lines, pretty simple. :) LINQ provides useful methods for this: Code File.ReadAllLines("path").SkipWhile(Function(ln) ln.IndexOf("searchvalue") == -1).Take(5)* - ShadyShadow - Apr 26, 2014 (Apr 26, 2014 04:30 PM)0xDEAD10CC Wrote: Are you trying to find the lines from the TextBox then or from the file directly? Using the file would be better. Find the line that you want to start at, then increment a count for how many lines you want to retrieve. When the count extends the limit, stop collecting the lines, pretty simple. :) File.ReadAllLines(location).SkipWhile(Function(ln) ln.IndexOf("Log In") = -1).Take(5) your code wasnt working so i removed the double = i think that was a prob but now i dont really know how to execute the command to make it popup in the richtextbox :/ * - Moen - Apr 26, 2014 I have just made everything on an other way. This will change the textbox 2 times since it is contains "Lastname" two times Code Dim FileReader As New IO.StreamReader("C:\Users\Moen\Desktop\Ny mappe\text.txt")* - ShadyShadow - Apr 26, 2014 (Apr 26, 2014 04:47 PM)The Moen Wrote: I have just made everything on an other way. Thanks thats working good but got 1 prob and that is if the currentline is like this "Lastname abc" it wont capture it is there a way to make it find "Lastname" no matter what is standing behind it? I also noticed that if i got 2 times lastname in it it wil only get the last one ;/ * - Moen - Apr 26, 2014 (Apr 26, 2014 04:53 PM)ShadyShadow Wrote: Thanks thats working good but got 1 prob and that is if the currentline is like this "Lastname abc" it wont capture it is there a way to make it find "Lastname" no matter what is standing behind it? then you use "startswith" as you have used before. (Apr 26, 2014 04:53 PM)ShadyShadow Wrote: Thanks thats working good but got 1 prob and that is if the currentline is like this "Lastname abc" it wont capture it is there a way to make it find "Lastname" no matter what is standing behind it? then you use "startswith" as you have used before. * - ShadyShadow - Apr 26, 2014 Got it working thanks, my code is: Code location = TextBox1.Text + "\" + ListBox1.SelectedItem.ToString* - 0xDEAD10CC - Apr 26, 2014 (Apr 26, 2014 04:41 PM)ShadyShadow Wrote: File.ReadAllLines(location).SkipWhile(Function(ln) ln.IndexOf("Log In") = -1).Take(5) Ahh, translated it in notepad from a test in C# that I did quickly (already had a C# project open), forgot to change that. Other than that, the only other thing I had to do was change the lambda and remove the semicolon. Thanks :) For a textbox you have to translate that IEnumerable result into a string. Code var obj = string.Join(Environment.NewLine, File.ReadAllLines("path").SkipWhile(ln => ln.IndexOf("searchvalue") == -1).Take(5).ToArray());Code Dim obj As String = string.Join(Environment.NewLine, File.ReadAllLines("path").SkipWhile(function(ln) ln.IndexOf("searchvalue") = -1).Take(5).ToArray()) |