Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Example: consider there are 5 names separated with a semicolon. I want to separate these 5 names.
consider,
Richard;Pareek;Elizabeth;Creig;Tomy
You would use the Split() function.
Example:
Dim input as String
Dim results() as String
input = "Richard;Pareek;Elizabeth;Creig;Tomy"
results = Split(input,";")
Note: If there are are spaces after the semicolons, be sure to include that in the second parameter of the Split function (so "; " instead of ";")
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am using VB.Net.
I need to remove all the repeated characters in textbox
For Example:
myy naaaame isss Johnn
to
my name is John
can anyone help me out please?
So even I, knowing zilch about VB.NET and RegEx figured it out in like 20 mins:
Sub Main()
Dim input As String = "myy naaaame isss Johnn"
' You need a regex group that matches any char: (.)
' ... and a back reference: \1
' ... and a count more than one: {1,}
Dim rgx As New Regex("(.)\1{1,}")
' use the regex to Replace by the first char of the match group
Dim output As String = rgx.Replace(input, New MatchEvaluator(Function(ByVal m)
Return m.Value.First
End Function))
End Sub
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
i am new to VB.
I am trying to retrieve the last value in the csv below.
0066,0055,0078
From this string, I want to fetch 0078.
From this string, I want to fetch 0078.
Try this,
Dim xString as String = "0066,0055,0078"
Dim xResult() as String = xString.split(",")
Dim xExtracted as String = xResult(xResult.length-1)
MsgBox(xExtracted)
a shorter alternative would be:
Dim xString as String = "0066,0055,0078"
MsgBox(xString.Substring(xString.LastIndexOf(",") + 1))
if you are going to use the function regularly consider creating an extension method
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 am trying to find which value is assigned to strA?
Dim dbleTest as Double = 0.25
Dim strA as String = dblTest.ToString("p")
If you correct your typo, and use Dim dlbTest As Double = 0.25, then this prints 25.00 % (locale specific, some locales may have different decimal separators).
Without that in place, the result will depend on the Option Explicit checking currently in place in the file, and potentially the value assigned to dblTest (if it exists in scope).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
I have a large text file with over 100k of lines. Some of the lines are duplicates. I would like to be a to dedupe these entries before processing them. I am using visual basic 2010 Express to write this.
Text file example:
132165
165461
646843
654654
321358
132165
165461
I want to dedupe these entries before processing them
You can use a HashSet(Of T)
Dim nodupes As New HashSet(Of String)(File.ReadLines(path))
For Each str As String In nodupes
' no duplicate here '
Next
Edit Since a HashSet(Of T) does not guarantee to preserve the insertion order you can use following code if you need to ensure this order:
Dim nodupeSet As New HashSet(Of String)
Dim nodupes = From line In File.ReadLines(path)
Where nodupeSet.Add(line)
For Each str As String In nodupes
' no duplicate here '
Next
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
Using Visual Basic, I want to replace a text within a String with another String. I do not know the location of this text within the String. How can I accomplish this?
Thanks for any help.
Try:
X = X.Replace("original"," toReplace")
Or this link:
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
' Input string.
Dim input As String = "Dot Net Not Perls"
' Use Regex.Replace with string arguments.
Dim output As String = Regex.Replace(input, "N.t", "NET")
' Print.
Console.WriteLine(input)
Console.WriteLine(output)
End Sub
End Module
Output
Dot Net Not Perls
Dot NET NET Perls
The replace method does not require you to know the location. You specify the original value, the string to look for, and the string to change it too. Very straight forward.
Dim aString As String = Replace("String to Search", "String to Find", "String to Replace With")