|
Hi,
I am using regex to lookup some data in a string. I do not have any prior experience using regular expression and would appreciate some help on the subject.
Here is my expression:
[^\.]\[(\s*\w+\s*)+\]
I am using it to match a string with square brackets where the first character is not a dot. So in the following string "[TableName].[FieldName]" I will only want to find "[TableName]". In "[Table1] INNER JOIN [Table2] ON [Table1].[Field1] = [Table2].[Field2]" I expect to find "[Table1]" and "[Table2]".
This seems to work in some cases, but miserably fails in others. For example, in the following string "[Table1], [Table2]", it only finds "[Table2]" since it expects to see some characted before the bracket.
Basically I want it to look at the first character before "[TableName]" only if there is one. I guess I need to make [^\.] optional but I was not able to find this option with regex syntax. Please help.
Thank you.
|
|
|
|
|
The part in square brackets can be matched with
\[\s*\w+\s*\]
To say "not following a dot" you need to use a look-behind assertion. With your expression, the non-dot character gets matched as part of the regex, which isn't what you're trying to get.
(?<!\.)\[\s*\w+\s*\]
This is perl 5 syntax, not sure what environment you're using.
--Mike--
Ericahist [updated Oct 26] | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
Michael,
Thank you for you reply. I am using Perl5 syntax and I was using this tool to test the expression: http://jakarta.apache.org/oro/demo.html. I guess, they just did not implement it there, because I kept getting an error (Malformed Regular Expression: Sequence (?<...) not recognized. )
Do you know any other tool I can use to test the expression.
Thanks.
|
|
|
|
|
|
Im trying to allocate a string in C(non-MFC) of a specified length.
I get an error message:
illegal constant expression
when trying to create buffer.
void parse(const int size)
{
char buffer[size];
...
}
This seems very simple, but I have tried everything. How do I go about doing this?
Kevin Shaffer
kshaff03@msn.com
|
|
|
|
|
char *buffer = (char *) malloc(size);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
The size of the array has to be known at compile time, so it can't be a variable. You need to use malloc or calloc instead.
--Mike--
Ericahist [updated Oct 26] | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
Thanks!
Kevin Shaffer
kshaff03@msn.com
|
|
|
|
|
<small>kshaff03 wrote:</small>
void parse(const int size)
{
char buffer[size];
...
} I think it valid in C99, not in C++.
Maxwell Chen
|
|
|
|
|
The problem is in your code
kshaff03 wrote:
void parse(const int size)
{
char buffer[size];
...
}
The problem lies in the way you've declared the array.
since char buffer[] is a static array meaning the compiler needs to know at compile time so it knows how much memory to allocate.
You're using a variable to size it. Where you should a constant or literal.
e.g.
#define MAX 100<br />
const unsigned int size = 50;<br />
<br />
inr main(void)<br />
{<br />
char foo[MAX];<br />
char bar[size];<br />
int fred[20];<br />
}
these 3 are all legal
your example should be coded as follows
void parse(const unsigned int &size)
{
char *buffer = new char[size];
...
delete[] buffer;
}
I'll send you an e-mail shortly
|
|
|
|
|
Hi,
I am trying to built an MFC application with an MDI Frame (CWinApp). Beside this, I have implemented a DLL in which I need to open an MFC based Dialog. Within the EXE, I just need to call DoModal and it works fine but here, the function that creates the dialog is in the DLL that is called by the main application.
It crashes in the function int CWnd::RunModalLoop(DWORD dwFlags) with an unhandled exception.
// pump message, but quit on WM_QUIT
if (!AfxGetThread()->PumpMessage())
{
AfxPostQuitMessage(0);
return -1;
}
By the way, I put Debugmultithreaded Dll in the settings of the application and the DLL.
What did I made wrong, please ????
MFC Beginer
|
|
|
|
|
I have two questions pertaining to serialization.
- I have nested classes but want save each class into seperate files how do go about doing this
and
- If want to able to open files in range of different extensions e.g *.csv, *.prn and *.txt. How is this achieved?
Again many thanks
Alton
|
|
|
|
|
1. Using MFC serialisation mechanisms, you don't. The assumption is made that a single file will contain the entire document. Indeed, use is made of a 'class dictionary' within an MFC archive file, unless you redo the serialisation from scratch.
2. There's a KB article (141921) which covers this nicely.
Steve S
|
|
|
|
|
I know to code it to return an object of ostream &, istream & or the classes that derived from them.
But how do you do it to return a reference to a CArchive?
Alton
|
|
|
|
|
If you're overloading the << and >> operators, chances are that you also have a CArchive& parameter. Simply return that.
Usually you'll have something like
<br />
friend CArchive& operator<<( CArchive& ar, myObj obj);<br />
friend CArchive& operator>>( CArchive& ar, myObj& obj);<br />
inside your class declaration for myObj .
So when you implement
<br />
CArchive& operator<<( CArchive& ar, myObj obj)<br />
{<br />
...<br />
return ar;<br />
}<br />
and similarly for the operator>> function.
Steve S
|
|
|
|
|
Steve S wrote:
friend CArchive& operator<<( CArchive& ar, myObj obj);
friend CArchive& operator>>( CArchive& ar, myObj& obj);
return ar;
I've those that inside a generic underived class but the compiler complains i.e. what the hell am I talking about.
do I:
- place the functions in the appropiate C++ and header files
- subclass them from CObject (which I don't want to do)
- or find the correct syntax (which is)
Alton
There's no problem, only solutions
John Lennon
|
|
|
|
|
Your C++ class must be derived from CObject to be serialisable anyway (see DECLARE_SERIAL, IMPLEMENT_SERIAL).
You would put those definitions in your 'base' class's header file, with the implementation, which is normally to call obj.Serialize(CArchive&ar), which you then implement.
You can then use these objects in your document's serialize method, using the operators, or alternatively, call the object's serialize method directly.
Does that help any?
Steve S
|
|
|
|
|
Does any one know how rows & columns can be added or remove on MSDataGrid control programatically. without using the CRecordset class. (there must be a way)
Many thanks
Alton
|
|
|
|
|
How to use UniCode in VC++ (CEdit control) or win32.
|
|
|
|
|
I don't understand the question. But for a project to support Unicode without any other changes, you need to turn that feature on. You'll then need to make sure all your char s are TCHAR s and your strings have the _T() macro around them. (If you are using pure Unicode, you can use wchar_t and the L prefix for strings.)
If you just want to make a single Win32 call using the Unicode function, use a Unicode string, if needed, and tack a 'W' on the end.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I am trying to open an htlm file to a specific bookmark without any success. I am tyring to use the ShellExecute command as follows:
ShellExecute(0, "open", "c:\test.html#Bookmark1", NULL, NULL, SW_SHOWNORMAL);
The result is that the program opens test.html in explorer, but does not got to Bookmark1. Is there any way to do this?
And while I'm on the subject, is there any way to do the same thing with PDF files (open a PDF file to a specific location?)
Thanks,
John
|
|
|
|
|
I'm automating our product build process. I have a native Win32 application that does some UI setup and updates version resources, and then it runs the build script. The build script is a .wsf (Windows Script File) that I want to run using CScript, the console script host.
My problem is this: If I call CreateProcess with CScript.Exe as the file to execute, the process starts, creates a console window, and exits immediately:
STARTUPINFO startup_info = { 0 };
char startup_title[128];
strcpy(startup_title,"Distribution build");
startup_info.cb = sizeof(startup_info);
startup_info.lpTitle = startup_title;
PROCESS_INFORMATION process_info = { 0 };
CreateProcess("CSCRIPT.EXE",
"//nologo DistributionBuild.wsf",
NULL,NULL,FALSE,
"C:\SC400.Build",
&startup_info,
&process_info); However, if I start CScript.Exe via the command interpreter, it runs correctly:
CreateProcess("CMD.EXE",
"CScript //nologo DistributionBuild.wsf",
NULL,NULL,FALSE,
"C:\SC400.Build",
&startup_info,
&process_info); Anyone have any ideas why this might be the case?
Software Zen: delete this;
|
|
|
|
|
You seem to be missing two parameters to CreateProcess() . I'm guessing that DWORD dwCreationFlags and LPVOID lpEnvironment are the ones.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks for your help, and sorry for the missing stuff. I'm using dwCreationFlags = 0 and lpEnvironment = NULL . I just reread the help for CreateProcess and realized I probably should use dwCreationFlags = CREATE_NEW_CONSOLE . Leaving the environment set to NULL should cause the new process to receive a copy of the existing one.
Software Zen: delete this;
|
|
|
|
|
What about the double backslash in the lpCurrentDirectory parameter? Does GetLastError() return a non-zero value in your first example of CreateProcess() ?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|