Click here to Skip to main content
15,913,854 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionMessage Closed Pin
24-Mar-18 5:47
serpzen-pakar-seo24-Mar-18 5:47 
RantRe: What is reflector? Pin
Eddy Vluggen24-Mar-18 6:51
professionalEddy Vluggen24-Mar-18 6:51 
QuestionGet MAC address only from internal ethernet connection Pin
blueye8923-Mar-18 11:58
blueye8923-Mar-18 11:58 
AnswerRe: Get MAC address only from internal ethernet connection Pin
Dave Kreskowiak23-Mar-18 13:44
mveDave Kreskowiak23-Mar-18 13:44 
GeneralRe: Get MAC address only from internal ethernet connection Pin
blueye8924-Mar-18 7:32
blueye8924-Mar-18 7:32 
GeneralRe: Get MAC address only from internal ethernet connection Pin
Dave Kreskowiak24-Mar-18 7:41
mveDave Kreskowiak24-Mar-18 7:41 
GeneralRe: Get MAC address only from internal ethernet connection Pin
blueye8924-Mar-18 8:59
blueye8924-Mar-18 8:59 
GeneralRe: Get MAC address only from internal ethernet connection Pin
Dave Kreskowiak24-Mar-18 9:21
mveDave Kreskowiak24-Mar-18 9:21 
GeneralRe: Get MAC address only from internal ethernet connection Pin
blueye8924-Mar-18 9:29
blueye8924-Mar-18 9:29 
QuestionBest Practice Question When Enumerating Directories Pin
Alan Burkhart22-Mar-18 5:24
Alan Burkhart22-Mar-18 5:24 
AnswerRe: Best Practice Question When Enumerating Directories Pin
Gerry Schmitz22-Mar-18 5:52
mveGerry Schmitz22-Mar-18 5:52 
SuggestionRe: Best Practice Question When Enumerating Directories Pin
Richard MacCutchan22-Mar-18 5:56
mveRichard MacCutchan22-Mar-18 5:56 
GeneralRe: Best Practice Question When Enumerating Directories Pin
Alan Burkhart22-Mar-18 11:39
Alan Burkhart22-Mar-18 11:39 
GeneralRe: Best Practice Question When Enumerating Directories Pin
Richard MacCutchan22-Mar-18 23:02
mveRichard MacCutchan22-Mar-18 23:02 
GeneralRe: Best Practice Question When Enumerating Directories Pin
Alan Burkhart23-Mar-18 8:31
Alan Burkhart23-Mar-18 8:31 
AnswerRe: Best Practice Question When Enumerating Directories Pin
Eddy Vluggen22-Mar-18 6:55
professionalEddy Vluggen22-Mar-18 6:55 
GeneralRe: Best Practice Question When Enumerating Directories Pin
Alan Burkhart22-Mar-18 11:40
Alan Burkhart22-Mar-18 11:40 
QuestionVb.net delete rows based on search criteria Pin
Andiko21-Mar-18 23:11
Andiko21-Mar-18 23:11 
AnswerRe: Vb.net delete rows based on search criteria Pin
Gerry Schmitz22-Mar-18 6:00
mveGerry Schmitz22-Mar-18 6:00 
GeneralRe: Vb.net delete rows based on search criteria Pin
Andiko22-Mar-18 22:20
Andiko22-Mar-18 22:20 
GeneralRe: Vb.net delete rows based on search criteria Pin
Gerry Schmitz22-Mar-18 22:40
mveGerry Schmitz22-Mar-18 22:40 
GeneralRe: Vb.net delete rows based on search criteria Pin
Andiko23-Mar-18 0:14
Andiko23-Mar-18 0:14 
AnswerRe: Vb.net delete rows based on search criteria Pin
Richard Deeming23-Mar-18 2:23
mveRichard Deeming23-Mar-18 2:23 
Try something like this:
VB.NET
Shared Iterator Function GroupAccounts(ByVal lines As IEnumerable(Of String)) As IEnumerable(Of IList(Of String))
    Dim currentAccount As List(Of String) = Nothing
    For Each line As String In lines
        If String.IsNullOrWhiteSpace(line) Then Continue For
        
        If String.Equals(line, "[account]", StringComparison.OrdinalIgnoreCase) Then
            If currentAccount IsNot Nothing Then Yield currentAccount
            currentAccount = New List(Of String)()
        End If
        
        If currentAccount IsNot Nothing Then
            currentAccount.Add(line)
        End If
    Next
    
    If currentAccount IsNot Nothing Then
        Yield currentAccount
    End If
End Function

Shared Iterator Function UngroupAccounts(ByVal groupedAccounts As IEnumerable(Of IEnumerable(Of String))) As IEnumerable(Of String)
    Dim started As Boolean = False
    For Each account As IEnumerable(Of String) In groupedAccounts
        If started Then
            Yield String.Empty
            Yield String.Empty
        End If
        
        For Each line As String In account
            Yield line
        Next
        
        started = True
    Next
End Function

Shared Function RemoveUser(ByVal groupedAccounts As IList(Of IList(Of String)), ByVal userToRemove As String) As Boolean
    Dim found As Boolean = False
    For index As Integer = groupedAccounts.Count - 1 To 0 Step -1
        If groupedAccounts(index).Any(Function (line) String.Equals(line, "user = " & userToRemove, StringComparison.OrdinalIgnoreCase)) Then
            groupedAccounts.RemoveAt(index)
            Found = true
        End If
    Next
    
    Return found
End Function
Usage:
VB.NET
Dim sourceLines As IEnumerable(Of String) = IO.File.ReadLines(textpath)
Dim groupedAccounts As IList(Of IList(Of String)) = GroupAccounts(sourceLines).ToList()
If RemoveUser(groupedAccounts, txtuser.Text.Trim()) Then
    Dim resultLines As IEnumerable(Of String) = UngroupAccounts(groupedAccounts)
    IO.File.WriteAllLines(textpath, resultLines)
End If

NB: This will remove any lines from the file which come before the first [account] header, remove any blank lines within an account, and ensure that all accounts are separated by two blank lines.

Now you need to review your password storage:
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Vb.net delete rows based on search criteria Pin
Andiko23-Mar-18 2:51
Andiko23-Mar-18 2:51 
GeneralRe: Vb.net delete rows based on search criteria Pin
Richard Deeming23-Mar-18 2:59
mveRichard Deeming23-Mar-18 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.