Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Could you make it faster?

Could you make it faster?

Scheduled Pinned Locked Moved C#
question
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ektoras
    wrote on last edited by
    #1

    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); OR richTextBox1.Text[i].**IsLetter**;

    J C 2 Replies Last reply
    0
    • E ektoras

      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); OR richTextBox1.Text[i].**IsLetter**;

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • E ektoras

        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); OR richTextBox1.Text[i].**IsLetter**;

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        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

        E 2 Replies Last reply
        0
        • C Christian Graus

          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

          E Offline
          E Offline
          ektoras
          wrote on last edited by
          #4

          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; } }

          1 Reply Last reply
          0
          • C Christian Graus

            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

            E Offline
            E Offline
            ektoras
            wrote on last edited by
            #5

            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?)

            C L 2 Replies Last reply
            0
            • E ektoras

              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?)

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • E ektoras

                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?)

                L Offline
                L Offline
                leppie
                wrote on last edited by
                #7

                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

                E 1 Reply Last reply
                0
                • L leppie

                  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

                  E Offline
                  E Offline
                  ektoras
                  wrote on last edited by
                  #8

                  :)Thank you very-very much leppie.

                  L 1 Reply Last reply
                  0
                  • E ektoras

                    :)Thank you very-very much leppie.

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups