|
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
|
|
|
|
|
Thank you Richard
But it doesn't seem to work.
It doesn't throw any error.
I executes fine but the user account still remains in text file.
Any other help or way would be appreciated
|
|
|
|
|
Then check the lines in the text file. You probably have a leading or trailing space, or extra spaces between "user", "=", and the username.
The line in the file needs to be exactly equal to:
user<space>=<space><trimmed username to delete>
For example:
user = usertest
If you have other characters on the line, it won't be found, and you'll need to change the search criteria.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
in fact it has lot of space
The format is exactly like this:
[account]
user<space><space><space><space><space><space><space><space><space><space> = usertest
pwd<space><space><space><space><space><space><space><space><space><space> = test
description<space><space><space><space><space><space><space><space><space><space> = test
email<space><space><space><space><space><space><space><space><space><space> = "test@test.com"
address<space><space><space><space><space><space><space><space><space><space> = "blah blah"
zip<space><space><space><space><space><space><space><space><space><space> = 255555
there are nearly 27 spaces (27 time I pressed space) between user and "=" sign
How can i deal with it?
thanks
|
|
|
|
|
I have tried something like this
'Dim countMatchingLines As Integer = 0
'Dim lines() As String
'Dim outputlines As New List(Of String)
'Dim searchstring1 As String = txtuser.Text.Trim()
'lines = IO.File.ReadAllLines(textpath)
'For Each line As String In lines
' If line.Contains(searchstring1) Then
' countMatchingLines = 7
' End If
' If countMatchingLines = 0 Then
' outputlines.Add(line)
' FileClose(1)
'
' IO.File.WriteAllLines(txtpath, outputlines.ToArray)
' FileClose(1)
' Else
' countMatchingLines -= 1
' End If
'Next
but the program enters in indefined loop and is not responding
|
|
|
|
|
Change the RemoveUser function to:
Shared Function RemoveUser(ByVal groupedAccounts As IList(Of IList(Of String)), ByVal userToRemove As String) As Boolean
Dim found As Boolean = False
Dim pattern As New Text.RegularExpressions.RegEx(
"^\s*user\s*=\s*" & Text.RegularExpressions.Regex.Escape(userToRemove) & "\s*$",
Text.RegularExpressions.RegexOptions.IgnoreCase)
For index As Integer = groupedAccounts.Count - 1 To 0 Step -1
If groupedAccounts(index).Any(Function (line) pattern.IsMatch(line)) Then
groupedAccounts.RemoveAt(index)
Found = true
End If
Next
Return found
End Function
Regular Expression Language - Quick Reference | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
it throws an error:
System.InvalidCastException: 'Unable to cast object of type 'System.Collections.Generic.List`1[System.Collections.Generic.IList`1[System.String]]' to type 'System.Collections.Generic.IEnumerable`1[System.Collections.Generic.IEnumerable`1[System.String]]'.'
Thank you for your time
I am a beginner in vb.net
|
|
|
|
|
Which version of Visual Studio are you using, and which version of .NET are you targeting?
The code I posted should work in .NET 4.0 or higher. If you're targeting an earlier version, you might need to change the parameter type on the UngroupAccounts function:
Shared Iterator Function UngroupAccounts(ByVal groupedAccounts As IEnumerable(Of IList(Of String))) As IEnumerable(Of String)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you very much Richard
It works like a charm
|
|
|
|
|
I have problem with Bytes Written randomly in textfile
Text replace correctly but when i open file with hex editor (HxD) and compare files some bytes replace with 81 45
Dim binaryfile As String = "E:\1.txt"
Dim txt As String
Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(932)
Using fr As StreamReader = New StreamReader(binaryfile, System.Text.Encoding.GetEncoding(932), False)
txt = fr.ReadToEnd
txt = txt.Replace("111", "2222")
End Using
My.Computer.FileSystem.WriteAllText(binaryfile, txt, False, System.Text.Encoding.GetEncoding(932))
Thanks
|
|
|
|
|
So, what is "2222" encoded in?
If you look in a txt that is encoded in "932", and replace a unicode string within that, might that lead to some weird bytes?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks a Lot
i have some Japanese Words Translate to English Words & Some Numbers E.g
txt = txt.Replace("男の子", "Boy")
|
|
|
|
|
I'm not sure if it is the cause or if it will work, but I'd expect the string-literal to be in unicode and would suggest to convert it to the codepage of the target-string before you replace it.
string boySearchString = System.Text.Encoding.Convert(
System.Text.UnicodeEncoding.Unicode,
System.Text.Encoding.GetEncoding(932),
System.Text.Encoding.Unicode.GetBytes("Boy"))
txt = txt.Replace("男の子", boySearchString) Same for the first argument in the Replace-method.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Could you imagine an artist painting without brushes or Michelangelo sculpturing without chisels? Obviously, no. The fact is similar to web developers who can’t build web apps of enterprise level without the hold of some right tools.
So lets discuss the top 5 list of helpful .Net tools which is used by application development experts.
|
|
|
|
|
|
"Let's discuss" is not a good way to ask for an answer. You can Google for a top 5, good luck.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Visual Studio 2010
Visual Studio 2012
Visual Studio 2013
Visual Studio 2015
Visual Studio 2017
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hii
I want to implement a chatbot using ASP.Net. I want to merge chatbot in my existing project. But, I don't know how to do it. Even, I am not familiar with the functionality of chatbot. Is there anyone who can help me?
Pooja Singh
|
|
|
|
|
I would suggest that you start with this[^]. You can't build it until you know how it works.
This space for rent
|
|
|
|
|
Hopefully this forum is appropriate for this question. No one seems to visit the graphics forum very often.
I need to be able to both import and export a 16 bit grayscale png file. I have found some help with importing but exporting is a big problem. I have found stack overflow references to Magick.NET but I cannot get this source to compile in VS 2012 as it requires build tools 141 and setting it to 110 results in errors, one of which is a missing dll that I cannot find using internet resources. I have already tried installing runtimes for later versions and for some reason they cannot be used. Probably because I use Windows 7.
Are there any other alternatives? Or advice on how to get a runtime of Magick.NET? I need to be able to read, manipulate (on an individual basis), and save 16 bit grayscale pixel values to a heightmap for importing into various terrain editors.
In terms of manipulating, I can probably use the native 48 bit rgb pixel format (please correct me if I am wrong) for display, convert, and then just read/write to the image directly but I still need to find a runtime that supports reading and writing to the 16 bit format. It would be nice however, if there was a library that did this automatically.
|
|
|
|
|
Try the GIMP API:
gimpconvert
gimpconvert — Conversions between RGB, indexed, and grayscale modes.
gimpconvert
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks for your quick reply. That looks like a native library. Not necessarily a problem but I am curious if there is a .NET wrapper. Also, is that a dll separate from the software or will I need to run GIMP? Is there any documentation on the class formats and uses? I am noticing things like "image_id" and other proprietary data types. One problem I may run into is that I currently need a 64 bit library as my project requires enough memory to produce extremely large bitmaps for illustrating data (I need around 2,061,341,604 bytes available for a 22701 x 22701 image in addition to the regular memory used by the application which is not small by itself).
|
|
|
|
|
I've used the app; not the API.
One way to "automate" GIMP is "scripting".
I think there's also a wrapper out there.
You have options ... and research.
One interfaces with native DLL's when one needs to. OLE. Type libraries. etc.
POV-Ray would be my next look ... more scripting.
Paint.NET ?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
If you save a bitmap with a png extension, you get a png file. Grayscaling will be described as a tip/trick or article.
--edit
..and you can load a png file into a bitmap. Give it a try
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes... been doing what you describe for years. However GDI+ does not import 16 bit greyscale as a 16 bit grayscale and does not export 16 bit grayscale. When it imports, it imports as a 32bit bgra which makes dealing with 16 bit grayscale values impossible because of the loss of information when converting 16 bit grayscale values to 8 bit rgb values. Exporting through the standard .NET drawing libraries is impossible as I have already read in several posts on this topic. My application needs to use grayscale values from 0-65535 in order to avoid a "shelved" appearance in the heightmaps I generate.
|
|
|
|