Find occurence in string with line number?
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
Hi guys,
Kind of stuck at this problem for a while...
I am trying to make a basic error checking routine which checks for open brackets or extra brackets.
The idea is to find { bracket with line numbers then find } with line numbers
Then start subtracting each occurrence until you are left with nothing or brackets. If you are left with brackets that mean these are extras or open.
How can I do this... :(
I have a code to find the occurence but I can't seem to get the line numbers. I am using an RTB.
-Toxikr3
Kind of stuck at this problem for a while...
I am trying to make a basic error checking routine which checks for open brackets or extra brackets.
The idea is to find { bracket with line numbers then find } with line numbers
Then start subtracting each occurrence until you are left with nothing or brackets. If you are left with brackets that mean these are extras or open.
How can I do this... :(
I have a code to find the occurence but I can't seem to get the line numbers. I am using an RTB.
Code: Select all
Hope some can help Dim strText As String
Dim strSearchText As String
Dim strSearchText2 As String
Dim index As Integer
Dim count As Integer
Dim count2 As Integer
strText = RTB.Text
strSearchText = "{"
strSearchText2 = "}"
count = 0
count2 = 0
For index = 0 To strText.Length - 1
If strText.Substring(index, 1) = strSearchText Then
count = count + 1
End If
Next
For index = 0 To strText.Length - 1
If strText.Substring(index, 1) = strSearchText2 Then
count2 = count2 + 1
End If
Next
Dim h As Integer
h = count - count2
If h <= -1 Then
ListBoxErrors.Items.Add("Missing {")
End If
-Toxikr3
Hello,
You can get the current line number from a richtextbox, for example show it in a messagebox:
You can get the current line number from a richtextbox, for example show it in a messagebox:
Code: Select all
Oh this will actually give you the exact line number of each occurrence, I put them into the ListBox while I was testing:MsgBox(RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart).ToString())
Code: Select all
I put it in your code like this:ListBox1.Items.Add(RichTextBox1.GetLineFromCharIndex(index).ToString())
Code: Select all
Hope that helps cooll;For index = 0 To strText.Length - 1
If strText.Substring(index, 1) = strSearchText Then
count = count + 1
ListBox1.Items.Add(RichTextBox1.GetLineFromCharIndex(index).ToString())
End If
Next
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Hello Codenstuff,
That was a nice code snippet. You should paste it in the Quick Snips section.
Thank you.
That was a nice code snippet. You should paste it in the Quick Snips section.
Thank you.
Thank you so much!
I will give this ago!
-Toxikr3
I will give this ago!
-Toxikr3
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023