VB.NET code dumper [closed] - vb.net

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hello im a beginner and i need to make a tool that will dump some codes that i need from a text file.
This is how the text file looks
79nxO´.[„Ò€D JƒÚY S 4 A4B67368-30F84CD6-930CEA07-C2645CDC
lÁ°uµ¥?_2¶›]éÚ[™tiipDAe LƒÚX S 4
1E2F44FA-19F77EC4-8212CEBF-6A196C36 é9£ð÷å“™—3-šÍïiÃä{r&GŠ JƒÚW
S 4 65735EC4-415C4232-91691832-8A8BE21F!VoS
Z˜©giàë½ÓX³ÁUhÛÇÖò LƒÚV S 4
CD3B3376-4638422A-A171BB50-00D194CC Û¾A#X "|ÂÒ9þ-¶=M¬°E¾+ JƒÚU
S 4
00D1996F-7F834C0F-A7B7F798-7CA393DE!¥£à«auA¾¼¢˜•ÈÖk}®˜¤ JƒÚT
S 4 8656E931-79CC8FFE-B11B168F-FEB84D92 ?Ø7pñBŽj¦Ù\
üXáæƒÕfø JƒÚS S 4 B72C3724-880944E8-B3B4CC58-EB7EB7E7 -
0íi/è+›N -‘”rU’[p$ JƒÚR S 4
CD9A4A87-1119464B-934C46AE-A36CF157 *µË0´eb€Ò;D Y6µ»Õ£”ê JƒÚQ
S 4 BC7F993F-A87F450F-A1BCC1E6-1FC9518D
(>þЬ0®žðR®ZV[óL¨¨lŒ;ôm¤ LƒÚP S 4
A3F8CC05-BABB4DB6-97E47D7E-7428D2CA ÜÌ ðs4¸ÌÏF¦Xf=êmHšÍÄô JƒÚO
S 4 C0A2FEE7-C0264D80-A1F8705A-EEA24595
#` IÐ]dÒ"ÎÑfþ0Äõ-®"€<³= JƒÚN S 4
E4D327F0-DE664C4E-BA1644BF-F0E5221C ¿Ptô(F3Ù™°Ú¹•žÒQÁü* JƒÚM
S 4 9671B975-D90D4854-9F3FAE97-A8F24DD2
ª°®õËÛH?y[ÛvN;ÿC‹[ JƒÚL S 4
82A717AB-8A0546EE-916657E9-FA87BD44 ={ÃPHÕÔŽš„ôгÒmâ ße5½j&u JƒÚK
S 4 9BD782BF-8E684DDC-B987FD8F-EF10871F
:—w°ALR-•ÿ•àz/N.ýœv˜arÚ LƒÚJ S 4
AC87845A-B7B64B22-A293D713-C46739F0 Ô¥60‘8Ä|I'Ýc¿!\¨ÃlçÒ JƒÚI
And this is for example a code "A4B67368-30F84CD6-930CEA07-C2645CDC"
I need to grab those out the file.

You can easily parse the targeted codes using a Regular Expression:
' copy & paste your string here, be sure to escape quotes properly
Dim s As String = "INSERT YOUR STRING HERE"
Dim rx As Regex
Dim m As MatchCollection
' This Regular Expression looks for a pattern like xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx
' where the x's are A thru F or Zero thru Nine
rx = New Regex("([A-F0-9]{8}\-[A-F0-9]{8}\-[A-F0-9]{8}\-[A-F0-9]{8})", RegexOptions.IgnoreCase)
m = rx.Matches(s)
For Each item In m
System.Diagnostics.Debug.Print(item.ToString)
Next

Maybe I don't fully understand, but looks like it's groups of 8 characters separated by hyphens you seek?
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim input As String = "the input you have above"
Dim pattern As String = "[A-Za-z0-9]{8}\-[A-Za-z0-9]{8}\-[A-Za-z0-9]{8}\-[A-Za-z0-9]{8}"
Dim m As Match = Regex.Match(input, pattern)
Do While m.Success
Console.WriteLine("'{0}' found at position {1}", m.Value, m.Index)
m = m.NextMatch()
Loop
End Sub
End Module
http://msdn.microsoft.com/en-us/library/0z2heewz.aspx

Related

Sort issue with integers [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am trying to make a leader board that puts highest scores at the top or left with this layout
99 - james,
90 - will,
80 - dan,
70 - phil,
60 - kevin,
570 - jim,
50 - ben,
40 - david,
30 - jose,
220 - peter,
20 - tony,
10 - nick,
The .sort command doesn't work for numbers 3 digits and up i have a list that i am tying to sort but it is not working.
This is what i am currently working with.
leaderboard.Sort()
leaderboard.Reverse()
It does sort numbers under 100 perfectly well this is the only issue i have.
Dim leaderboard As New List(Of String)
Using Reader As New StreamReader("C:\Users\1111\OneDrive\Documents\Leaderboard.txt")
While Reader.EndOfStream = False
leaderboard.Add(Reader.ReadLine())
End While
End Using
leaderboard.Sort()
leaderboard.Reverse()
First I made a Structure as a template to hold your data. It has 2 properties. One to hold the Score and one to hold the name.
Private Structure Leader
Public Property Score As Integer
Public Property Name As String
End Structure
The code starts out by creating a new list of Leader (the name of the structure).
I used the File class from System.IO (you will need to add this to the list of Imports at the top of the code file). .ReadAllLines returns an array of strings, each element is a single line from the text file.
Then we loop through each line, splitting the line by the hyphen. This will give your an array of strings with 2 elements. Before you try to convert the the first element to an Integer be sure to trim off any spaces. The second element of the array will contain the name and need to be trimmed. I also replaced the comma with an empty string.
Finally, a bit of Linq magic orders the list in descending order by score into another list. Function(lead) is a function that takes each item in the original list and tests its Score property. I called .ToList at the end so orderedLeader could be display in a DataGridView.
Private Sub OPCode()
Dim leaderboard As New List(Of Leader)
Dim lines = File.ReadAllLines("leaderboard.txt")
For Each line In lines
Dim splitLine = line.Split("-"c)
Dim sc = CInt(splitLine(0).Trim)
Dim nm = splitLine(1).Trim.Replace(",", "")
leaderboard.Add(New Leader With {.Score = sc, .Name = nm})
Next
Dim orderedLeaderbord = leaderboard.OrderByDescending(Function(lead) lead.Score).ToList
DataGridView1.DataSource = orderedLeaderbord
End Sub

How do I convert the the middle number coming from an presser in vb.net to asterisk in form of an account number [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Am working on a banking app and I want to send sms to the users and I want the account number to be in this form 2719**5849 and the account number is coming from a textbox
trying daShier's solution i got 1234**8910 for 12345678910
number 7 was removed
this should work for you on a button click and on any length size because it does not remove any chars
Dim intg As Integer = TextBox1.Text.Length / 2
Dim str As New List(Of String)
Dim str2 As New List(Of String)
For Each c As Char In TextBox1.Text
str.Add(c)
Next
For i As Integer = 0 To TextBox1.Text.Length - 1
If i <= intg AndAlso i >= intg - 2 Then
str2.Add("*")
Else
str2.Add(str(i))
End If
Next
TextBox2.Text = String.Join("", str2.ToArray())
changed to be 3 asterisk
I would not convert each character in the middle to an * because it provides unnecessary information on the number of characters in the account number. Instead, I would just use a fixed number of * (two, as in your example) to represent all the middle characters:
UPDATE:
I added a check for the length, since I assume from your comments that you are trying this when the text in the textbox changes...
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim ObfuscatedAccount As String
If TextBox1.Text.Length > 8 Then
ObfuscatedAccount = TextBox1.Text.Substring(0, 4) &
"**" & TextBox1.Text.Substring(TextBox1.Text.Length - 4, 4)
TextBox2.Text = ObfuscatedAccount
End If
End Sub

How to remove specific lines of a file in vb.net [duplicate]

This question already has answers here:
Delete specific lines in a text file using vb.net
(3 answers)
Closed 5 years ago.
I've got a file with a list of the names:
Bill
Jack
Sam
Sarah
I want to be able to remove specific lines so if I asked it to remove "Jack" then the new list would become:
Bill
Sam
Sarah
What I've got so far:
Imports System.IO
Dim filename As String = "C:\names.txt"
Dim StreamReader As New StreamReader(filename)
Dim LineCount As Integer = File.ReadAllLines(filename).Length
For i = 0 to LineCount - 1
If StreamReader.ReadLine() = "Jack" Then
'Remove This Line
End If
Next
You could get this down to one real line of code (not counting declaring the filename variable, since I could easily hard-code that):
Dim filename As String = "C:\names.txt"
File.WriteAllLines(filename, File.ReadAllLines(filename).Where(Function(l) l <> "Jack"))

Delete spaces in cell - VBA [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have the following string in excel:
" 163,40 3,10 1,86 163,30 163,40 167,00 163,30 435862329"
And I have no problem to split up this column into 8 individual columns - one for each block of data. But I saw that the first column - here 163.40 is truncated so it becomes 163 - that is from a float to an integer. I realized later thats because the numbers is preceeded by four spaces - " 163.40".
So my question is how to delete these four spaces - and ONLY these four first spaces.
That would solve my problem.
Any ideas?
Use Mid function like used below for your problem.
Mid(text, 5, Len(text))
Assuming that your source string is in cell A1 and you need the 8 columns data in row 2 ; please refer to below code :
Function SplitMyData()
Dim var As Variant
var = Split(Trim(Range("A1").Value), " ", , vbTextCompare)
For i = 0 To UBound(var)
Cells(2, i + 1).Value = var(i) 'Pasting vals in row 2
Next
End Function
You can change the source and destination cell references as per your requirements. :)

How to search for an integer in a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I'm making a program that will give you the result of a sum when the input is unstructured. Please see the following:
Input:
whats 20 + 26
Output:
46
I already know how to search for text in a string (If text.IndexOf("hello") >= 0 Then)...
I have no idea how to use the two integers for an addition equation.
Here's a quick example of how to start doing this with regular expressions. This won't be bulletproof against anything you throw at it, but it should make for a good start.
Be sure to add : Imports System.Text.RegularExpressions to your .vb file
'This string is an example input. It demonstrates that the method below
'will find the sum "2345+ 3256236" but will skip over things like
' if + .04g
' 1.23 + 4
' etc...
Dim input As String = _
"aoe%rdes 2345+ 3256236 if + .04g rcfo 8 3 . 1.23 + 4 the#r whuts"
Dim pattern As String = "\s\d+\s*\+\s*\d+(?=\s|$)"
For Each _match As Match In Regex.Matches(input, pattern)
Dim a = _match.Value.Split("+"c) 'Match extracts "2345+ 3256325"
Dim x As Integer
Dim y As Integer
If Integer.TryParse(a(0), x) AndAlso Integer.TryParse(a(1), y) Then
Console.WriteLine("Found the Sum : " & x & " + " & y)
Console.WriteLine("Sum is : " & x + y)
Else
Console.WriteLine("Match failed to parse")
End If
Next
The regular expression can be broken down as
\s '(definitely) one whitespace
\d+ 'followed by any number of integer digits
\s* 'followed by (possibly) a whitespace
\+ 'followed by (definitely) a "+"
\s* 'followed by (possibly) a whitespace
\d+ 'followed by any number of integer digits
(?=\s|$) 'followed by (definitely) either a whitespace or EOL
Read more here :
Regular Expression Language - Quick Reference
.NET Framework Regular Expressions
Regular Expressions Reference
Parse the two integers into two integer variables - we'll call them x and y. Then add their results.
Dim x as Integer
Dim y as Integer
Dim result as Integer
'parse your integers- you indicate you already know how to do this
'add the results
result = x + y
'now print out the result