Hack Forums
[.NET] Delete spesific line until last 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: [.NET] Delete spesific line until last line (/showthread.php?tid=5710046)



Delete spesific line until last line - Shikatanai - Sep 3, 2017

As title said, I need a help about it

Text:
Code
this text1
this text11
this text11
this text11

blabla

this text2

My code:
Code
Dim lines As New List(Of String)
        lines = txt1.Lines.ToList
        Dim FilterText = "(blabla )"

        For i As Integer = lines.Count - 1 To 0 Step -1
            If Regex.IsMatch(lines(i), FilterText) Then
                For u As Integer = lines.Count - 1 To lines(i) Step -1
                    lines.RemoveAt(u)
                Next
            End If
        Next
txt1.Lines = lines.ToArray

I want to delete line (blabla) until last line (this text2), but have a error in this part For u As Integer = lines.Count - 1 To lines(i) Step -1
Any help? thankyou


* - Barret - Sep 3, 2017

As the title "spesific" :P states , regex or fixed index locations (ex SubString)


* - HFDone - Sep 4, 2017

TextString.Split("blabla ")(0)


* - Hawk HF - Sep 5, 2017

It's C# instead of VB and I'm sure there's a shorter way to code this, but I don't feel like putting forth the effort to clean it up right now.



[Image: BWFjx7k.png]


* - th3s3cr3t0n3 - Sep 6, 2017

(Sep 3, 2017 09:07 PM)Shikatanai Wrote:  As title said, I need a help about it

Text:
Code
this text1
this text11
this text11
this text11

blabla

this text2

My code:
Code
Dim lines As New List(Of String)
        lines = txt1.Lines.ToList
        Dim FilterText = "(blabla )"

        For i As Integer = lines.Count - 1 To 0 Step -1
            If Regex.IsMatch(lines(i), FilterText) Then
                For u As Integer = lines.Count - 1 To lines(i) Step -1
                    lines.RemoveAt(u)
                Next
            End If
        Next
txt1.Lines = lines.ToArray

I want to delete line (blabla) until last line (this text2), but have a error in this part For u As Integer = lines.Count - 1 To lines(i) Step -1
Any help? thankyou

What error are you getting?


* - 0xDEAD10CC - Sep 6, 2017

Code
For u As Integer = lines.Count - 1 To lines(i) Step -1

lines:
Code
Dim lines As New List(Of String)

syntax:
Code
For ? As {Type} = Min To Max (Step Increment)

The problem should be clear.


* - th3s3cr3t0n3 - Sep 7, 2017

(Sep 6, 2017 03:02 PM)0xDEAD10CC Wrote:  
Code
For u As Integer = lines.Count - 1 To lines(i) Step -1

His code didn't say that did it??


* - 0xDEAD10CC - Sep 7, 2017

If you look at the first post...

[Image: vvtBnN0.png]

Or the post you quoted here: https://hackforums.net/showthread.php?tid=5710046&pid=55794306#pid55794306

It would have taken you a few seconds to verify it.


* - th3s3cr3t0n3 - Sep 8, 2017

(Sep 7, 2017 09:24 AM)0xDEAD10CC Wrote:  If you look at the first post...

[Image: vvtBnN0.png]

Or the post you quoted here: https://hackforums.net/showthread.php?tid=5710046&pid=55794306#pid55794306

It would have taken you a few seconds to verify it.

I'm fcking confused man. I look at all references and still don't see it like that. Oh well, I agree with your point though that wouldn't work lol.

EDIT: Oh fuck what a complete dick. I need more sleep. I see it now the second loop... what a fucking jerk my brain is.