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
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 4 years ago.
Improve this question
I want to count files in a folder based on their sizes. For example, how many files that are less than 512KB and how many files that are more than 512KB. Please help me.
Below sub-routine will help you to get the count
Sub GetFileDetails(ByVal sFolderPath As String, ByRef Filelessthan512KB As Integer, ByRef FileMorethan512KB As Integer)
Dim sFiles() As String = Directory.GetFiles(sFolderPath)
For Each file As String In sFiles
Dim oFileDetails As New FileInfo(file)
If (oFileDetails.Length / 1024) < 512 Then
Filelessthan512KB = Filelessthan512KB + 1
Else
FileMorethan512KB = FileMorethan512KB + 1
End If
Next
End Sub
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 4 years ago.
Improve this question
[so i put the string like "hello world" and want to change "l" to "a" then i need to count the no. of changed letters how do i count the change letters only? help pls[1]: https://i.stack.imgur.com/Wu1PF.jpg
a possible solution would be computing the length difference between the input string and the same one with find string substituted with "":
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
newStringTB.Text = inputTB.Text.Replace(findTB.Text, replaceTB.Text)
noOfReplacedTB.Text = Len(inputTB.Text) - Len(Replace(inputTB.Text, findTB.Text, ""))
End Sub
just change:
"Button1" to your actual command button name
"newStringTB", "findTB", "replaceTB" and "noOfReplacedTB" to your actual textboxes names
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 4 years ago.
Improve this question
I have an array that contains characters converted from a word via .ToCharArray method. I would like to check how many times a letter occurred in this array (word). How can I do this?
One way is a lookup:
Dim letterLookup = yourCharArray.ToLookup(Function(c) c)
' For example the letter e, note that it's case sensitive '
Dim eLetterCount As Int32 = letterLookup("e"c).Count()
This is efficient and has the advantage that you can even check letters which aren't contained in the String/Char(), you will get 0 as result.
By the way, you don't need to use ToCharArray, you could use this code on with original string.
If you wanted to list all contained letters:
Dim allLetters As IEnumerable(Of Char) = letterLookup.Select(Function(kv) kv.key)
If you wanted to ignore the case, so treat e and E as equal:
Dim letterLookup = yourCharArray.tolookup(Function(c) c, StringComparer.CurrentCultureIgnoreCase)
For example the word 'tent'. The program would check which letter
occurs more than once (t) and find the position in the array (in this
case 0,3). It will also find the position in the array of the other
letters.
Then i would use a different approach also using LINQ:
Dim duplicateLetterPositions As Dictionary(Of Char,List(Of Integer)) = yourCharArray.
Select(Function(c, index) New With {.Char = c, .Index = index}).
GroupBy(Function(c) c.Char).
Where(Function(grp) grp.Count > 1).
ToDictionary(Function(grp) grp.Key, Function(grp) grp.Select(Function(x) x.Index).ToList())
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 6 years ago.
Improve this question
Lets say i have a textbox containing the string "hello".
Is there a way in which can i check that the 3rd character of textbox.text = "l"?
We are talking about visual basic, of course.
Thanks!
You could use this function
Private Function checkCharacter(thisString As String,
searchCharacter As Char,
index As Integer)
Try
Return thisString(index) = searchCharacter
Catch
Return False
End Try
End Function
Call it like this
Dim result As Boolean = checkCharacter(TextBox1.Text, "l"c, 2)
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
If I declared an array of strings, and the strings are each a Sub name, how can I call the Sub of that name without needing an if statement?
Example pseudo code:
Set String Array = {"sub1","sub2","sub3"}
for each String str in Array
call str 'where str is a Sub
next str
I do know how to create an array and call Subs; I just don't know how to call a Sub using a string value.
Try this:
Application.Run (str)
I just learned about this by doing something similar. You can also pass a variable to that sub by doing:
Application.Run (str, "YourValue")