|
Hi all. I'm trying to do a regex that will find bool variables in my C# code that don't contain the word 'Is' in the name. I have this:
^(\s+(private|public|protected))[\s]+bool[\s]+[\w]+(Is)[\w]+[\s]*[^\(\w]
which matches variables, but not methods, that DO contain 'Is'. I tried (^Is), but that doesn't work, for obvious reasons. Can anyone suggest how I go about getting the match I want ?
Thanks.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian Graus wrote:
which matches variables, but not methods, that DO contain 'Is'. I tried (^Is), but that doesn't work, for obvious reasons. Can anyone suggest how I go about getting the match I want ?
Try searching MSDN for negative lookahead.
Everytime I need to use it I need to re-read it ten times until I get it working, but it does exactly what you need.
When will someone come up with something more readable than regexes?
Yes, even I am blogging now!
|
|
|
|
|
Thanks - negative lookahead is exactly what I was trying to emulate
It's all working now, which means I've just about finished. You're right, regex is SO illegible. I really like doing them though, they are cool. Something more legible would be nicer, but not as much fun !!!
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
CG, I see you have your problem solved, but I thought I would pass along a useful tool in case you haven't seen it before. It's call The Regulator[^], a free regular expressions testing and learning tool. Very useful.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Thanks. I had to do 25 or so regexes, and I used expresso. I'll download this one and give it a go as well, though.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I would like to develop an application that acts as a compiler editor, as an example when the user write "if" in the text the word's color is changed into blue for instance; how can I use the richTextbox to develop such that application? what are the functions needed to develop such that application?
If you gave me a sample application it is thankful.
m_h_shehab@hotmail.com
Great thanks in advance.
M.Shehab
|
|
|
|
|
Use a regular expression (look at System.Text.RegularExpressions namespace) to search for your keywords inside the text as the user types it. When a match is found, change it's color to blue using properties like richTextBox.SelectedTextColor .
Any remotely useful information on my blog will be removed immediately. There are 10 kinds of people in the world. Those who have heard of the ubiquitous, overused, worn-out-like-an-old-shoe binary "joke" and those who haven't.
Judah Himango
|
|
|
|
|
There is an article here on CP; I don't have the link right off hand that discusses this. I believe that it was written in VB.NET however it should take little effort to convert this over to C#. Try using the Search[^] page.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I'm trying to find a tool that can convert this cpp source to cs source.
Can anyone help?
|
|
|
|
|
Blubbo wrote:
Can anyone help?
Probably not, there are too many differences between the languages that you couldn't guarantee that your conversion would perform correctly. If you have a particular question on mapping from C++ to C# feel free to post it for additional help.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I think you are right - such tool will be grat, but not easy to build. I've played a little with porting some Linux KDE Games written in C++ to C# and they works with minor changes. There were 3 most important points: changing method names (good code editor will do the magic) and playing with structures and pointers.
h.
|
|
|
|
|
Hi ive been working on a program and i need to send keys to another program, ive used user32 sendmessage to send api codes and i can get sendkey to send to the top level program but i want a way thats kind of a cross between them both.
I'd like a way to send the keys like with sendkey but to any process running like the sendmessage. Ive looked though alot of things on send message and i know you can change some numbers to get it to send differnt types of messages but havent found if you can just send keys.
Any help would be wonderfull.
|
|
|
|
|
|
Like i said in the first post, ive used send key but it only works on the top program wich isn't always applicable, unless thier is some way of making it work on any running program
|
|
|
|
|
S0200356 wrote:
Like i said in the first post, ive used send key but it only works on the top program wich isn't always applicable, unless thier is some way of making it work on any running program
No, you can't. SendKeys uses the Windows API SendInput, which will generate keypresses as if they came from the keyboard driver, and will generate the proper messages for the topmost program.
I don't recall where I read that you need to use this API, and that SendMessage wasn't a reliable API for emulating keypresses. Sorry if I can't be more useful than this.
I think you can find almost everything about the keyboard in Windows here[^]
Yes, even I am blogging now!
|
|
|
|
|
hi there!
I don´t know if I this doubt is for this forum. (sorry if it isn´t)
I´m working with the WMEncoderLib and I want to know when the encoding process ends.
I saw a MSDN example and the last statement is like this...
// Start the encoding process.
// Wait until the encoding process stops before exiting the application.
Encoder.PrepareToEncode(true);
Encoder.Start();
Console.WriteLine("Press Enter when the file has been encoded.");
Console.ReadLine(); // Press Enter after the file has been encoded.
this example suppose that we press enter when the encode process finish. But I can I know that this process is finish?!! How can I change this code to make the program exit when the encoding finish?!
Thanks
|
|
|
|
|
ee99035 wrote:
But I can I know that this process is finish?!!
You could attempt to make the call asynchronous through BeginInvoke and EndInvoke . Have you looked into this?
- Nick Parker My Blog | My Articles
|
|
|
|
|
I already solve my problem
thanks
|
|
|
|
|
|
Ok here's my problem:
I've created a setup project that installs my application on a computer, and creates a shortcut to this application on the Desktop.
This application uses a configuration file that is supposed to be in the same directory as the application (save to "./configfile.cfg"). This file is updated every time the application is closed.
Also, in my application, the user can save a different type of file by himself, using a SaveFileDialog.
The problem is:
When the user saves a file during a session with my application (say, in My Documents), the configuration file ends up in the same directory (ie. My Documents).
BUT when the user doesn't save any file during the session, the configuration file ends up at the right place.
Does anyone know what's going on???
|
|
|
|
|
Could you post the code for saving with SaveFileDialog and saving of your configuration file.
www.troschuetz.de
|
|
|
|
|
Ok here's the code for my configuration file:
FileStream file = new FileStream("./config.cfg", FileMode.OpenOrCreate, FileAccess.Write);<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
formatter.Serialize(file, network);<br />
file.Close();
And here's my code for saving the user file with a SaveFileDialog:
saveFile.Filter = "Events Tables files (*.etf)|*.etf|All files (*.*)|*.*" ;<br />
saveFile.FilterIndex = 1;<br />
DialogResult result = saveFile.ShowDialog();<br />
if(result == DialogResult.Cancel)<br />
return;<br />
FileStream file = new FileStream(saveFile.FileName, FileMode.OpenOrCreate, FileAccess.Write);<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
formatter.Serialize(file, events);
file.Close();
|
|
|
|
|
Don't use the relative path string to open the filestream to your config file. Better
string path = Application.StartupPath + Path.DirectorySeparatorChar + "config.cfg";
FileStream file = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
www.troschuetz.de
|
|
|
|
|
Thanks a lot!
|
|
|
|
|
Hi guys,
i am using c# in my web app for the first time and have no clue how to get retrieved records to bind to a textbox.
i have successfully connected to the db and have databinded a few datagrids but i can't seem to get the textbox to show a value retrieved from the db.
please could someone be kind enough to show me the correct way to go about this.
thanks so much
|
|
|
|