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
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
Working on a discount field. The field needs to only allow positive numbers between 0 and 100. Field is a text box. Using visual studio and visual basic.
You could use a NumericUpDown control along with its Minimum, Maximum, and DecimalPlaces properties.
However, if you don't like the scroll box and really want to use a TextBox, it can be done like this:
Private min As Decimal = 1
Private max As Decimal = 100
Private Sub txtDiscount_TextChanged(sender As Object, e As EventArgs) Handles txtDiscount.TextChanged
Dim i As Decimal
Static lastValidText = ""
If (txtDiscount.Text = "") OrElse (Decimal.TryParse(txtDiscount.Text, i) AndAlso (i >= min And i <= max)) Then
lastValidText = txtDiscount.Text
Else
txtDiscount.Text = lastValidText
txtDiscount.SelectionStart = txtDiscount.TextLength
End If
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 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 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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim reader As StreamReader = My.Computer.FileSystem.OpenTextFileReader(TextBox1.Text)
Dim a As String
a = reader.ReadLine
RichTextBox1.Text = RichTextBox1.Text + a
Label5.Text = RichTextBox1.Text.Substring(5, a.Substring(5, a.Length))
reader.Close()
End Sub
Hello. I am trying to read a text file and put the numbers in different variables. The textfile is like this
IMAGE
Every time i run the code it comes out with an error. What should i do?
What is it that you're trying to do with this line?
Label5.Text = RichTextBox1.Text.Substring(5, a.Substring(5, a.Length))
This part: a.Substring(5, a.Length) returns a string, but the second argument of Substring expects an integer, so it is causing an error.
Substring looks like this: Substring(startIndex As Integer, length As Integer). You are trying to pass a string into the second argument.
Simply dropping the second argument from that line seems that it would do what you want it to:
Label5.Text = RichTextBox1.Text.Substring(5)
If these types of problems are frequently affecting you, I highly suggest you turn Option Strict on in Visual Studio. Here are some instructions on how to do so.
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
when i click the "browse" button I need to browse for a txt/xml file and place the data of that file in the text box.So for this I tried with a code but I was not successful.So can you help me with the vb.net code for this
If think that the problem is in your if statement. Here is an example of what you can do:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If My.Computer.FileSystem.FileExists("Your Path") = True Then
TextBox1.Text = My.Computer.FileSystem.ReadAllText("Your Path")
Else
MsgBox("ERROR - File Not Found")
End If
End Sub
End Class
Notice the change I did in the If Statement. Hoped it helped.