Could you make it faster?
-
In a very large richTextBox I want to find all letters. Is there something faster than :
char[] letters={ 'a','b','c','d','e','f','g','h','i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', 'T','U','V','W','X','Y','Z'} ; richTextBox1.Text.**IndexOfAny**(letters, i);
ORrichTextBox1.Text[i].**IsLetter**;
-
In a very large richTextBox I want to find all letters. Is there something faster than :
char[] letters={ 'a','b','c','d','e','f','g','h','i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', 'T','U','V','W','X','Y','Z'} ; richTextBox1.Text.**IndexOfAny**(letters, i);
ORrichTextBox1.Text[i].**IsLetter**;
I'm not sure how much faster it'd be, but have you looked at System.Text.RegularExpressions? Optionally, you could check the text each time a new character is entered to see if it's a letter, then just set some boolean flag indicating whether all characters are letters.
Tech, life, family, faith: Give me a visit. Judah Himango
-
In a very large richTextBox I want to find all letters. Is there something faster than :
char[] letters={ 'a','b','c','d','e','f','g','h','i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', 'T','U','V','W','X','Y','Z'} ; richTextBox1.Text.**IndexOfAny**(letters, i);
ORrichTextBox1.Text[i].**IsLetter**;
I doubt you could make it slower.... Use RegEx, or IsChar on each character as they are typed, as has been suggested. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
I doubt you could make it slower.... Use RegEx, or IsChar on each character as they are typed, as has been suggested. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
I want to make blue color all words
int position=0; char[] KeywordsCanStartWith = {'_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q', 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I', 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'} ; char[] KeywordsEndBeforeApears = {' ','\t','(',')',',','.',';','\n','[',']','{','}','+','-','*','/',':', '=','<','>','|','\\','&','%','?','$','!','"','#','\'','@','^'} ; bool LogVar; //give blue color to all keywords(=words) void giveColorToKeywordsInRTB(object sender, System.EventArgs e) { position=0; KeywordStartsHere=-1; caretPos=richTextBox1.SelectionStart; LogVar=true; LockWindowUpdate(richTextBox1.Handle); richTextBox1.Select(0, richTextBox1.Text.Length); richTextBox1.SelectionColor = Color.Black ; while(LogVar) { KeywordStartsHere = richTextBox1.Text.IndexOfAny(KeywordsCanStartWith , position); if(position<0) break ; if(position==KeywordStartsHere) { position = richTextBox1.Text.IndexOfAny(KeywordsEndBeforeApears, position) ; if(position==-1) position=richTextBox1.Text.Length-1 ; else position--; richTextBox1.Select(KeywordStartsHere, position-KeywordStartsHere+1); richTextBox1.SelectionColor = Color.Blue ; } } if(++position > richTextBox1.Text.Length-1) LogVar=false; } }
-
I doubt you could make it slower.... Use RegEx, or IsChar on each character as they are typed, as has been suggested. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
Judah Himango and Christian It is a source code editor that makes use of /*, */, //, "" to make some pieces green etc. So I must jumb from point to point. That's why I prefer to use .IndexOf instead of .IsLetter. Could you give me an idea of how to use the solution you suggest(with a litle piece of code if it is possible?)
-
Judah Himango and Christian It is a source code editor that makes use of /*, */, //, "" to make some pieces green etc. So I must jumb from point to point. That's why I prefer to use .IndexOf instead of .IsLetter. Could you give me an idea of how to use the solution you suggest(with a litle piece of code if it is possible?)
Just look up regular expressions in MSDN. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
Judah Himango and Christian It is a source code editor that makes use of /*, */, //, "" to make some pieces green etc. So I must jumb from point to point. That's why I prefer to use .IndexOf instead of .IsLetter. Could you give me an idea of how to use the solution you suggest(with a litle piece of code if it is possible?)
The RichTextBox will choke badly once you have a few more lines (try 1000+). If you want fast (close to linear) ( :) ) look at the code of my editor (link below). Even if your detection routines are fast, the RichTextBox will choke on both its find methods and it drawing methods, and there is NOTHING you can do about that, except write your own editor from scratch like i did, and integrate a proper lexical analyser to do the work. top secret
Download xacc-ide 0.0.3 now!
See some screenshots -
The RichTextBox will choke badly once you have a few more lines (try 1000+). If you want fast (close to linear) ( :) ) look at the code of my editor (link below). Even if your detection routines are fast, the RichTextBox will choke on both its find methods and it drawing methods, and there is NOTHING you can do about that, except write your own editor from scratch like i did, and integrate a proper lexical analyser to do the work. top secret
Download xacc-ide 0.0.3 now!
See some screenshots -
If you do a CVS check you will find more recent code, but the project has gone a bit stale (woman & work makes leppie a dull boy :( ) top secret
Download xacc-ide 0.0.3 now!
See some screenshots