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. RichTextBox.Find method fails to find known string.

RichTextBox.Find method fails to find known string.

Scheduled Pinned Locked Moved C#
algorithmsquestion
5 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.
  • M Offline
    M Offline
    Mark F
    wrote on last edited by
    #1

    In the following method, the 'startPos' variable always contains -1 when searching for a string that is known to exist within the RichTextBox.

        private string GetHeadingInnerHtml()
        {
            int startPos = myRich.Find("", 0, RichTextBoxFinds.None);
            int endPos = 0;
    
            if (startPos >= 0)     // Fails here! startPos value is 0xffffffff
            {
                endPos = myRich.Find("", startPos + 6, RichTextBoxFinds.None);
                myRich.SelectionStart = startPos;
                myRich.SelectionLength = ( endPos - startPos );
                return myRich.SelectedText;
            }
            return string.Empty;
        }
    

    :wtf: Any ideas why? Thanks.

    L realJSOPR P 3 Replies Last reply
    0
    • M Mark F

      In the following method, the 'startPos' variable always contains -1 when searching for a string that is known to exist within the RichTextBox.

          private string GetHeadingInnerHtml()
          {
              int startPos = myRich.Find("", 0, RichTextBoxFinds.None);
              int endPos = 0;
      
              if (startPos >= 0)     // Fails here! startPos value is 0xffffffff
              {
                  endPos = myRich.Find("", startPos + 6, RichTextBoxFinds.None);
                  myRich.SelectionStart = startPos;
                  myRich.SelectionLength = ( endPos - startPos );
                  return myRich.SelectedText;
              }
              return string.Empty;
          }
      

      :wtf: Any ideas why? Thanks.

      L Offline
      L Offline
      Lev Danielyan
      wrote on last edited by
      #2

      What's your source text? The Find method which accepts string will not find text, if it is more than on one line.

      Regards, Lev

      1 Reply Last reply
      0
      • M Mark F

        In the following method, the 'startPos' variable always contains -1 when searching for a string that is known to exist within the RichTextBox.

            private string GetHeadingInnerHtml()
            {
                int startPos = myRich.Find("", 0, RichTextBoxFinds.None);
                int endPos = 0;
        
                if (startPos >= 0)     // Fails here! startPos value is 0xffffffff
                {
                    endPos = myRich.Find("", startPos + 6, RichTextBoxFinds.None);
                    myRich.SelectionStart = startPos;
                    myRich.SelectionLength = ( endPos - startPos );
                    return myRich.SelectedText;
                }
                return string.Empty;
            }
        

        :wtf: Any ideas why? Thanks.

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        If it returns -1, it ain't there. Are you sure there's no Text property in the myRich object?

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        M 1 Reply Last reply
        0
        • M Mark F

          In the following method, the 'startPos' variable always contains -1 when searching for a string that is known to exist within the RichTextBox.

              private string GetHeadingInnerHtml()
              {
                  int startPos = myRich.Find("", 0, RichTextBoxFinds.None);
                  int endPos = 0;
          
                  if (startPos >= 0)     // Fails here! startPos value is 0xffffffff
                  {
                      endPos = myRich.Find("", startPos + 6, RichTextBoxFinds.None);
                      myRich.SelectionStart = startPos;
                      myRich.SelectionLength = ( endPos - startPos );
                      return myRich.SelectedText;
                  }
                  return string.Empty;
              }
          

          :wtf: Any ideas why? Thanks.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          This worked OK for me. I put the following text into a RTB and it found the details with no problem. <html> <head> <some tesxttlkajsdlfj asdf> </head> </html> If you debug your application, what does myRich.Text contain when you step into this method?

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          My blog | My articles | MoXAML PowerToys

          1 Reply Last reply
          0
          • realJSOPR realJSOP

            If it returns -1, it ain't there. Are you sure there's no Text property in the myRich object?

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            M Offline
            M Offline
            Mark F
            wrote on last edited by
            #5

            I set a watch for the value of myRich.Text property. Then I noticed that an earlier called method cutoff part of the <head> element's starting tag so naturally the Find method did not find it. :doh: Thanks, Mark

            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