|
-
Apr 11th, 2001, 07:40 PM
#1
Thread Starter
Hyperactive Member
OK, here's the deal.
I'm using a richtextbox for an editor app.
I need to search through a lot of the characters in a file to look for a match - I need to do this recursively,
so speed is important - I may have several thousand characters to test.
I can get the current position of the caret with this:
curpos = editbox.selstart
I can get the char at the caret with this:
curchar = mid(editbox.text,curpos,1)
However, when I open some text files, there seems to be extra control chars at the end of each line.
This makes the Mid() function inaccurate since it counts these extra chars, even though SelStart does not.
Without processing the entire file (speed is imprtant here) how can I account for these extra chars?
Is there another way to get the "current char" without using Mid() ?
Also, if I Select the current char, it'll flash the window a lot and be quite slow.
Any suggestions?
-
Apr 11th, 2001, 08:25 PM
#2
how does it count those characters? you are capturing 1 char past the caret??
What happens with the odd chars? or better yet...what is the odd chars?
1 thing you could do is a replace()
load file into a single string...
Replace the odd char with a blank "" then load it into the RTB?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Apr 11th, 2001, 08:44 PM
#3
PowerPoster
You can use the .sellength to select one character at a time. You see the cursor go across teh screen, but that looks cool when u do it.
-
Apr 12th, 2001, 01:35 AM
#4
Thread Starter
Hyperactive Member
I'm using this for a parenthesis matching routine in a code editor I'm writing.
Put the cursor next to a ) or ( or [ or ] or { or } and it'll find the match if one exists.
I'm counting the chars like this:
For i = curpos + 1 To Len(editBox.Text)
curchar = Mid(editBox.Text, i, 1)
If curchar = startChar Then
count = count + 1
ElseIf curchar = endChar Then
count = count - 1
End If
If count = 0 Then
editBox.SelStart = curpos - 1
editBox.SelLength = i - curpos + 1
Exit For
End If
Next i
I find the initial char, say a ")" then I look for companions - ")" and "(" - the same char is plus 1, the
companion is minus one - when I hit zero - I've found the match. If I never hit zero, there is no match.
I search backwards or forwards based on the initial char - "(" sets a forward search , ")" sets a bacwards
search....
But I never know when I'm going to get a file with "extra" linefeeds! SO, in one case, my count may be accurate but the same method will be inaccurate with a screwy file....
As well, I can't use SelLength cause it's not only very slow, but the textbox flickers like crazy.
I'm working with code files that may have over a thousand lines - that's a lotta chars.
I need a faster, more accurate way to get the char under the cursor.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|