|
-
Nov 20th, 2007, 08:07 PM
#1
Thread Starter
Junior Member
[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.
-
Nov 20th, 2007, 08:40 PM
#2
Hyperactive Member
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.
-
Nov 20th, 2007, 09:07 PM
#3
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.
-
Nov 20th, 2007, 09:10 PM
#4
Thread Starter
Junior Member
Re: [2008] Finding text, and changing it
 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 !
-
Nov 20th, 2007, 09:32 PM
#5
Re: [2008] Finding text, and changing it
 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.
-
Nov 20th, 2007, 09:50 PM
#6
Thread Starter
Junior Member
Re: [2008] Finding text, and changing it
Oh, ok. Sorry, I am kinda new to C#. How do i use the regular expressions though? :?
-
Nov 20th, 2007, 10:19 PM
#7
Hyperactive Member
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.
-
Nov 20th, 2007, 10:22 PM
#8
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.
-
Dec 3rd, 2007, 04:48 PM
#9
Re: [2008] Finding text, and changing it
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
|