|
|
Hi!
I've got a string:
string str = ">200 <=250";
and a regular expression:
Regex rx = new Regex ("^(>=?|<=?|=) *[0-9]+ *$");
the way I see it (understand regex) with
rx.Matches(str);
I should get two matches (">200" and "<=250")
but I get an empty collection..
did I do something wrong?
thanks for any help!!
Seishin
life is study!!!
|
|
|
|
|
You probably want this:
Regex rx = new Regex ("(>=|<=|=)\d+");
x.Matches(str);
This matches all numbers with a ">", ">=", "<=" before it, no matter where in the text it is. It also matches in-text, it would for example also match "thisisatext>=500", which you could exclude by adding "\b"'s for word-end-checking, like this:
Regex rx = new Regex ("\b(>=|<=|=)\d+\b");
|
|
|
|
|
thanks..
"(>=?|<=?|=) *\d+"
works fine.. i wanted to match '>' '<' as well so i had to add '?' after '='.
life is study!!!
|
|
|
|
|
Two things:
1. You are REQUIRING your match to occur for the entire string since you are using '^' and '$' at the beginning and end, respectively, and
2. You may need to escape the '>' and '<' characters.
Implementing both of the above, your regex becomes...
Regex rx = new Regex(@"(\>=?|\<=?|=)\s*\d+\s*"); Let me know if this works as desired,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
yaeh. the problem was with ^ and $.. removing them solved the issue..
thanks!
life is study!!!
|
|
|
|
|
Hi guys,
I have a problem regarding threads in my application. I got a Form in my app which owns a class derived from WarnModule (see http://pastebin.com/m72a3f841[^]) that periodically triggers some kind of warning (i got different implementations of that). The problem is that the finalizer of the WarnModule does not get called when the application that owns the WarnModule-derived class wants to exit and the still running thread in WarnModule then blocks the application from exiting.
How can i solve this issue?
Thanks in advance,
Lucas
|
|
|
|
|
You will need to some how signal the thread that it is time to exit. One way to do this (logically, but I leave coding it up to you) is as follows...
1. Create a shared boolean object initialized to false called "TimeToExit"
2. Periodically check the value of TimeToExit from the running thread. If true, exit.
3. From the main thread, after setting TimeToExit to "True" and waiting for some amount
of time without the thread ending (the maximum thread response time), kill the thread :( Note that you will NOT need to make the boolean thread safe, as one thread is reading and the other is writing, and no inconsistent state can occur here. Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
That's what i am already doing, but I dont know where to set that flag from. The ApplicationExit event does not get fired until the object has been disposed, which never happens because the Thread keeps running.
|
|
|
|
|
What event triggers you wanting to exit the application? Form.Closing? Somewhere in your code there will be SOME event (that I can't guess) which is triggering this desire to exit. If it is user initiated, then there must be some event like Form.KeyPress, Button.Click, Form.Closing, etc. If it is initiated by code somewhere, then just add that line to set the bool at that point. If you still cannot figure out where to put the code for this, explain what event is triggering the application exit and I can try to help some more.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I can signal the Thread to exit after Application.Run() returned, so that solves my problem.
But what I really wanted to do was to make the object clean up it's own mess (as you are supposed to do it in OOP), but I didn't succeed in that.
I tried stopping the Thread in the Finalizer and in Dispose() (i derived the class from IDisposable), neither worked.
|
|
|
|
|
Hi all,
I am using the Find method if the RichTextBox to search for a certain word within the control. But how can I move to the line where the text was found ??
int indexToText = richTextBox1.Find(text, RichTextBoxFinds.MatchCase);
if(indexToText >= 0)
{
}
Many Thanks
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Can't you just do the following?
int indexToText = rtb.Find(text, RichTextBoxFinds.MatchCase);
if(indexToText >= 0) {
rtb.Select(indexToText, 0);
rtb.ScrollToCaret();
} Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hi,
Thanks for the response, but when I try and search for the next word that matches the find it keeps repeating the same line within the RichTextBox. What am I doing wrong?
This is the code I'm trying...
if (this.activeRichEdit.Find(textBox1.Text, 0, activeRichEdit.Text.Length, options) != -1)
{
int endIndex = this.activeRichEdit.Text.Length;
int findIndex = this.activeRichEdit.Find(textBox1.Text, 0, endIndex, options);
this.activeRichEdit.SelectionColor = System.Drawing.Color.DarkRed;
activeRichEdit.Select(findIndex, 0);
activeRichEdit.ScrollToCaret();
}
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
int foundIdx = 0;
while ((foundIdx = rtb.Find(textBox1.Text, foundIdx, rtb.TextLength, options)) >= 0) {
rtb.Select(foundIdx, textBox1.TextLength);
rtb.SelectionColor = System.Drawing.Color.DarkRed;
foundIdx += textBox1.TextLength;
}
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
|
Hi
i think the richtextbox should do this automatically for you. if you call Find , it'll select the text that was found, and should ensure that the selection is visible.
if it does not ensure that it's visible you can do this by calling ScrollToCaret()
greets
m@u
|
|
|
|
|
Hi All,
I want to make a component,circular in shape, which inherits the property of button eg change the label, resize etc,also on which I will apply Bitmap using C# for my working project.
Pls help me.
Somit
|
|
|
|
|
Override the OnPaint method, draw a circle using the bitmap to fill. Override the OnMouseEnter, OnMouseLeave, and OnMouseDown events to set the style you want and to refresh the button's client area.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
How I can document my C# project?
What must be considered and what should be avoided?
I want to know the best approach. If some one has a sample document then please send me on sami@xpert-tech.com or samibaba.khan@gmail.com
Thank you in advance.
|
|
|
|
|
I like to use N-Doc for internal documentation (turns your three-backslash xml comments into html documentation). It is a free download, so just search online for it.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
NDoc only really works on .NET 1 and .NET 1.1. If you're using higher versions of the framework, you should look at using Sandcastle.
|
|
|
|
|
i have 2 forms called "A" and "b" .when the button in the form "A" clicks the form "b" loads and thorugh the form "b" i want to add a listitem to a listview in form "A". i made the listview public though can't access the listview without creating a new form.
How can i do this without creating new form object?? in my application i have a win.. form and
|
|
|
|
|
One of the better methods for doing this is to implement the Model View Controller (MVC) pattern. Have a read of this pattern and then see how it helps to solve this issue. (Alternatively, you could use an Observer pattern, but the MVC is probably going to be a bit easier for you to get your head round).
|
|
|
|
|
could you please tell me links where i can read about model view controls..
|
|
|
|