Click here to Skip to main content
14,272,647 members

.NET Framework

 
AnswerRe: Best Practice Question When Enumerating Directories Pin
Eddy Vluggen22-Mar-18 6:55
mveEddy Vluggen22-Mar-18 6:55 
GeneralRe: Best Practice Question When Enumerating Directories Pin
Alan Burkhart22-Mar-18 11:40
memberAlan Burkhart22-Mar-18 11:40 
QuestionVb.net delete rows based on search criteria Pin
Andiko21-Mar-18 23:11
memberAndiko21-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
memberAndiko22-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
memberAndiko23-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:
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:
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
memberAndiko23-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 
GeneralRe: Vb.net delete rows based on search criteria Pin
Andiko23-Mar-18 4:13
memberAndiko23-Mar-18 4:13 
GeneralRe: Vb.net delete rows based on search criteria Pin
Andiko23-Mar-18 4:21
memberAndiko23-Mar-18 4:21 
GeneralRe: Vb.net delete rows based on search criteria Pin
Richard Deeming23-Mar-18 4:22
mveRichard Deeming23-Mar-18 4:22 
GeneralRe: Vb.net delete rows based on search criteria Pin
Andiko23-Mar-18 4:46
memberAndiko23-Mar-18 4:46 
GeneralRe: Vb.net delete rows based on search criteria Pin
Richard Deeming23-Mar-18 4:58
mveRichard Deeming23-Mar-18 4:58 
GeneralRe: Vb.net delete rows based on search criteria Pin
Andiko23-Mar-18 5:11
memberAndiko23-Mar-18 5:11 
QuestionEncoding Hex Write Data Pin
Orochi9727-Feb-18 6:08
memberOrochi9727-Feb-18 6:08 
QuestionRe: Encoding Hex Write Data Pin
Eddy Vluggen27-Feb-18 8:02
mveEddy Vluggen27-Feb-18 8:02 
QuestionRe: Encoding Hex Write Data Pin
Orochi9727-Feb-18 22:45
memberOrochi9727-Feb-18 22:45 
AnswerRe: Encoding Hex Write Data Pin
Eddy Vluggen28-Feb-18 1:13
mveEddy Vluggen28-Feb-18 1:13 
QuestionBest Tools For .NET Development Pin
Priyanka Kale26-Feb-18 0:31
memberPriyanka Kale26-Feb-18 0:31 
AnswerRe: Best Tools For .NET Development Pin
Richard MacCutchan26-Feb-18 0:32
protectorRichard MacCutchan26-Feb-18 0:32 
AnswerRe: Best Tools For .NET Development Pin
Eddy Vluggen26-Feb-18 0:38
mveEddy Vluggen26-Feb-18 0:38 
AnswerRe: Best Tools For .NET Development Pin
Gerry Schmitz26-Feb-18 5:15
mveGerry Schmitz26-Feb-18 5:15 
QuestionImplementation of Chat Bot Pin
Member 1362292025-Feb-18 18:46
memberMember 1362292025-Feb-18 18:46 

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.