Results 1 to 9 of 9

Thread: [2008] Finding text, and changing it

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    A hot place
    Posts
    27

    [2008] Finding text, and changing it

    Ok, I am writing a sort of editor, and I am trying to implement simple Syntax highlighting. Basically all i want to do is search through a rich text box as it is typed into, and find and bold certain words, but i am unsure as to how i would do this. Thanks in advance.

  2. #2
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: [2008] Finding text, and changing it

    I think your dealing with a regex pattern. Here try to look at this thread and hope that helps.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Finding text, and changing it

    What you're specifically asking for is not that difficult but to actually implement syntax highlighting in a RichTextBox without your app grinding to a halt is a little more difficult. If you search the entire text every time then it will be all but unusable. Many people have asked about syntax highlighting before. I'd suggest a forum search to see what advice has been provided. I'd suggest searching the VB.NET forum too, as principles will be the same and code can be easily converted.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    A hot place
    Posts
    27

    Re: [2008] Finding text, and changing it

    Quote Originally Posted by fret
    I think your dealing with a regex pattern. Here try to look at this thread and hope that helps.
    Regex doesn't seem to exist in C# 2008 !

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Finding text, and changing it

    Quote Originally Posted by Seismosaur
    Regex doesn't seem to exist in C# 2008 !
    Of course it does. Go to the MSDN documentation and look up the Regex class. You'll then see which namespace it's a member of and which assembly it's declared in. If your project doesn't already have a reference to that assembly you can add one. You can then refer to the class qualified by its namespace or else import its namespace with a 'using' statement, just like every other class.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Location
    A hot place
    Posts
    27

    Re: [2008] Finding text, and changing it

    Oh, ok. Sorry, I am kinda new to C#. How do i use the regular expressions though? :?

  7. #7
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: [2008] Finding text, and changing it

    You use as a filter of your every string pattern declaration to validate whether Alphabet, AlphaNumeric, Integer, Postive Integer, Floating point numbers. In terms it is used as a pattern to search a specific string. The one I'd give you the link gives a simple example so from there you can get an idea of it, but sad to say I'm no expert of these.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Finding text, and changing it

    That's not a one line answer. You should read the documentation for the Regex class first, to get a general idea of how you can use it assuming that you have a valid pattern. Then you should search the Web for regular expression tutorials, of which there would be several. They are not limited to .NET at all.

    That said, if you're looking for key words then regular expressions is probably not appropriate. Regex is for finding patterns of characters, e.g. three letters followed by two numbers, but if know exactly what words you're looking for then that's not really what you need. You would probably just use IndexOf to find a substring. The question is, whatever you choose to do, when are you going to do it? Ideally you'd only look at the current word each time the text changes.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2008] Finding text, and changing it

    I played with this concept a while back
    http://vbforums.com/showthread.php?t=481008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width