|
I need that Regex won't return match if the string starts with another substring, for example "abc".
In detail, "abcde " shouldn't match, but "abg ", "gbc " and "afcgr " should match.
I know the [^abcde] syntax that works for characters, but I couldn't figure out way for substrings.
It is possible to do this with Regex?
I need it to be done through Regex, not String class methods.
Thanks.
|
|
|
|
|
|
I think you missed the point.
"abc" should not match.
I want to match any combination of three characters, except the above sequence.
I can do it as well with two chars. For example, if i want to match anything except "ab", i can use (?:a[^b])|(?:[^a].) .
But when it comes to three or more characters, i find no way. Maybe I miss something.
Thanks.
|
|
|
|
|
"[^(abcd)]+" seems to be working
a better way would be: "^(?!abcd).+"
(I'm not sure if (?!x) is a valid expression in the C# Regexes)
|
|
|
|
|
sb777 wrote:
Maybe I miss something.
Perhaps
It is infact matched just not returned, well at least not as a named group. Al you have to do is check is Groups["good"].Success . As long as your precedence is correct, you can match and 'eleminate' alot of data at once.
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
TyronX,
yous second suggestion did answered my question. thanks a lot. BTW, the first one isn't correct.
leppie,
Your suggestion could also fit in another constraints, but thanks for the new information.
|
|
|
|
|
I'm making a class to manage textures, and i have them stored in a hashtable. Now I have two possible objects I could use as a key, a texturedata object that describes the texture, or a compressed string format dataobject (like a Key or an ID string).
Would a hash table lookup a string quicker than an object?
Cheers guys.
Cata
|
|
|
|
|
|
Ok, that's cool. Now another question.
What would take up more space in memory overall? A class with 5-6 parameters, say a short string, few ints, and enumerations. Or a single string of say 40 charachters?
I'm assuming that i will have a few hundred objects with these values in them, so i'd like to make it efficient for space. If i remember correctly, a string is a value type, so it will take up space for each instance of itself. Now, if 100 objects have this string key, it will be 100x the string value. But if I use an object, they are handled as refference type, and only 1 exists, but many objects would have access to it.
Am I right? Would an object form be less expensive for memory?
On the other hand, some of these objects may only be used once, and therefore could benefit from the smaller space that the string would be.
Of course, I could always go with pointers to strings... but it could be a headache.
what do you think?
Cheers
Cata
|
|
|
|
|
Is this for an embedded system? Otherwise quibbling about the overhead for a few hundred objects seems pretty silly.
Anyway, since you didn't say how long the "short string" is, there's no way to guess.
As far as the value type stuff goes, there can be many references to one string. In fact, many identical string literals in your code will all result in the same string in a "constant pool" that is shared (that is, all the places where it is used in your code will instead have a reference to that one constant string instance).
> Now, if 100 objects have this string key, it will be 100x the string value.
No, that's not correct. Of course, there is an exception and it depends on how the references are created. If you create a hundred of these:
class MemHawg
{
string name;
public MemHawg( string name )
{
this.name = new string( name );
}
}
Then it will take more memory than this would:
class MemMiser
{
string name;
public MemMiser( string name )
{
this.name = name;
}
}
The first one makes a (somewhat useless) copy of the the string passed in, while the second one just has a reference to the one string. So in the second case, you'll have 100 objects that all refer to the same one string.
Of course, the latter implementation makes more sense, since there isn't much sense in duplicating immutable objects.
Matt Gerrans
|
|
|
|
|
Hellos friends ,I need that my printer print my document in mirror,I want manipulate this from c#,anyone help me.
Regards bigmega
|
|
|
|
|
In your even thandler for the PrintDocument.PrintPage event (or override of OnPrintPage if extending PrintDocument , which is usually a good idea for encapsulation) you need to apply a transformation matrix to the Graphics object by assigning the identity matrix to the Graphics.Transform property (the world transform) with either M11 or M22 negated to flip on the y-axis or x-axis, respectively.
For example:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class FlipExample : Form
{
static void Main()
{
Application.Run(new FlipExample());
}
RectangleF left;
RectangleF right;
PointF[] triangle;
StringFormat format;
Matrix flipTransform;
FlipExample()
{
Text = "Flip Example";
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw |
ControlStyles.UserPaint, true);
format = StringFormat.GenericDefault;
format.Alignment = StringAlignment.Center;
OnResize(EventArgs.Empty);
}
void DrawCaption(Graphics g, RectangleF r, string caption)
{
g.DrawString(caption, Font, SystemBrushes.ControlText,
r, format);
}
void DrawTriangle(Graphics g, RectangleF r, bool flip)
{
if (flip)
{
g.Transform = flipTransform;
g.TranslateTransform(r.X, 0f, MatrixOrder.Append);
}
else
{
g.ResetTransform();
}
g.FillPolygon(SystemBrushes.ControlText, triangle);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
DrawCaption(g, left, "Normal");
DrawCaption(g, right, "Flipped and Translated");
DrawTriangle(g, left, false);
DrawTriangle(g, right, true);
}
protected override void OnResize(EventArgs e)
{
float halfWidth = Width / 2f;
float halfFont = Font.Height / 2f;
left = new RectangleF(0f, 0f, halfWidth, (float)Height);
right = new RectangleF(halfWidth, 0f, halfWidth, (float)Height);
flipTransform = new Matrix(-1,0,0,1,halfWidth,0);
triangle = new PointF[] {
new PointF(halfWidth, halfFont),
new PointF(halfWidth, (float)Height
- SystemInformation.CaptionHeight - halfFont * 2f),
new PointF(0f, Height / 2f)};
base.OnResize(e);
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am trying to make windows installer uninstall the old version and install a new version upon a new release. I found a property RemovePreviousVersions and set it to true.
Accorting to documentation UpgradeCode must not change and ProductCode must be difference. After the install, I go to the Add/Remove programs and see both versions on the list. Is there something that I'm missing?
|
|
|
|
|
Asad Hussain wrote:
Accorting to documentation UpgradeCode must not change and ProductCode must be difference.
That is correct. So is it? To easily find out, download the MSI SDK from http://msdn.microsoft.com/platformsdk[^] which installs Orca.msi into the Platform SDK's Bin directory. Then install that. You can open the MSI packages in Orca. Find the Property table and make sure that for both packages the UpgradeCode property value is the same.
For major installs, you must also change the major version number. Minor installs only change the minor version number. For changes to the build(third) number, the ProductCode should not change. Read Patching and Upgrades[^] in the MSI SDK documentation for more information about package versioning rules.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a similar problem, on looking at the MSI tables it appears there is some default 1.0.0 version, and from what I can see your version needs to supersede that.
From the Upgrade table:
{742006A9-F10B-4A30-AD73-B05C1875B9AE} 0.0.2 258 NEWERPRODUCTFOUND <br />
<br />
{742006A9-F10B-4A30-AD73-B05C1875B9AE} 1.0.0.0 0.0.2 256 PREVIOUSVERSIONSINSTALLED
Any thoughts?
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
If you take a look at the documentation for the Upgrade table in the MSI SDK (online at http://msdn.microsoft.com/library[^], of course) you'll see that the bits Attribute column are flags and you can see their values.
What's happening above is that the first record is only for detection of newer products, but does not remove them. The second record will remove any products between 1.0.0.0 (inclusive) to 0.0.2 (exlusive).
With that in mind, you should've started your version at 1.0.0 and must have set RemovePreviousVersions to true originally. If you modify your table manually you can fix these problems and in future updates not have to worry about it.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I am having an error for which I have no clue whether the problem is with my machine / IDE or something other. I checked out the code from CVS (C# ) and when I try compiling the code, I get the following error:
fatal error CS0013: Unexpected error writing metadata to file 'filepath\filename.dll' -- 'Unspecified error '
The project that I am building is in C# and its a class library type. I have Visual Sudio .NET 2003 installed on my machine running windows XP. I tried looking up MSDN and what I could see there was just these 3 possible options and none of them work.
>>Compiler Error CS0013
>>Unexpected error writing metadata to file 'file' — 'description'
>>The .NET Framework common language runtime failed to emit metadata. This could be a number of problems:
>>1. Disk full.
>>2. Corrupt Visual Studio installation; reinstall Visual Studio.
>>3. Corrupt common language runtime; reinstall the common language runtime.
I have no clue what is wrong. I have tried google / MSDN but of no avail. Please help me.
Thanks in Advance,
Divick
|
|
|
|
|
Most likely this is problem #3. Visual Studio .NET is just a client that uses the CLR and the designer classes defined mostly by the BCL (base class library), implementing a few interfaces internally to facilitate design-time features.
Go to Add/Remove Programs and find the entry for the Microsoft .NET Framework and uninstall it. Either download it (whichever version you need: VS.NET 2002 requires .NET 1.0 and VS.NET 2003 requires .NET 1.1) from http://msdn.microsoft.com/netframework[^] or install it from the CD that contains VS.NET. Make sure you have all necessary updates from Windows Update (or you can download them separately from the URL above as well).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have already tried this option but it doesn't work. I don't have the update CD instead I tried connecting directly but the setup says that "No service releases are available at this time."
Divick
|
|
|
|
|
That's for Visual Studio .NET. VS.NET != .NET. VS.NET is only an Integrated Development Environment (IDE). The .NET Framework is a separate component. You must download the .NET Framework 1.0 SP3 or .NET Framework 1.1 SP1 from either Windows Update or the download center, which is linked from http://msdn.microsoft.com/netframework[^].
VS.NET is what you use to write programs for the .NET Framework, while the .NET Framework is a runtime and base class library.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have tried that as well. I downloaded .NET Framework 1.1 SP1 from the link above and then tried to recompile, but again the same error.
Divick
|
|
|
|
|
You may have to uninstall both the .NET Framework and Visual Studio .NET, then. Make sure you uninstall them both and clean-up the directories by deleting %WINDIR%\Microsoft.NET\Framework\v1.1.4322 and %ProgramFiles%\Microsoft Visual Studio .NET 2003 (assuming that's where you install VS.NET). Then re-install.
Something has been corrupted and I don't know what. Be sure to search for that error in the Microsoft Knowledge Base at http://support.microsoft.com/search[^] and see if you find anything.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Good day. I have this scenario wherein I have a number of 'user controls' to be placed on C# forms. These controls are reused which means that they are placed on the forms of our application, depending on the user. I want to keep all of the forms' events in a single separate class called "Events.cs".
In summary, these is how it goes:
1. The user chooses which controls to be included in the form.
2. Upon raising an event for a user control (clicking a button), the control will raise an event listed on the separate class (Events.cs).
3. The events class will be the one to access the main form (where the user controls are placed); and do the necessary changes to the form and perform commands like database access.
Is this possible? What is the best approach in doing this?
|
|
|
|
|
The container that accepts these controls must add an event handler for whatever events you want to handle. That event handle is defined by the class contained in Events.cs (that's just a filename, BTW, not a class).
So that the container control can add handlers the event handlers - either instance methods or static methods - must be either public or internal .
An example of adding an event handlers follows:
control1.Click += new EventHandler(someClass.control1_Click); Please note that what you actually call the event handler method doesn't matter (so long as it doesn't conflict with another method or property name) and that different events have different delegates (event handlers), so be sure to read the documentation for the event before wiring it up to an event handler (because that event handler must have the same method signature as the delegate that defines the event).
For more information about handling and raising events, read Handling and Raising Events[^] in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks very much Heath. I tried what you said, but the problem is, I can't find a way for the events class (on the events.cs filename) to communicate or talk back to the form where the control is located.
Like for example this very simple scenario.
- the user control is simply a button named 'btnControl'
- i then drag the 'btnControl' to a form named
'contrainer', which also has a textbox in it called 'txtTest', to verify if the user control can talk to the form via a separate events class.
- remember the events of all the controls, which includes 'btnControl' are raised on a separate class called 'events'. Meaning the user controls have does not communicate directly to the form it has been placed.
- so upon click the 'btnControl', i raise an event on the 'events' class, which will change the text of 'txtTest' to "Add button clicked". But i can't seem to communicate back to the opened form, without opening a new form.
Thanks.
|
|
|
|
|