|
my requirement is if a string starts with "L#",or "G#" or "X#" i dont want to replace some part of the string. Otherwise I will replace.
for example: string identifier="L#1234";
In this case I dont want to replace any thing there. Otherewise I would replace some part of the string there.
|
|
|
|
|
Then why worry about using a regular expression? There's no need to do this - sometimes it's just easier to directly manipulate a string - in this case, if the second character isn't hash then you don't need to check the first character.
|
|
|
|
|
got it..thanks. sometimes we think too much for simple ones.
|
|
|
|
|
It depends on the declaration of identifier. Assuming it is a string, here is my shortest replacement:
new System.Text.RegularExpressions.Regex(identifier.ToString());
Others already explained why it does the same your code does.
And yes, the ToString() part is necessary.
|
|
|
|
|
Luc Pattyn wrote: And yes, the ToString() part is necessary.
Ummm... what?
|
|
|
|
|
Exactly what I said.
|
|
|
|
|
I have a partial class that extends my property class, which is a table provided by the entity framework. I am extending that class to supply a string that contains a full address from address parts (number, street name, etc...)
It looks like this, in brief:
public partial class Property
{
public string fullAddress
{
get
{
string address = this.number.ToString();
if (!string.IsNullOrEmpty(this.direction))
{
address += " " + this.direction;
}
return address;
}
}
}
When I type this. Intellisense gives me the option to use direction or _direction. What is the difference and which should I use for getting?
I know I have read this somewhere before but it has slipped my mind.
Cheers, --EA
|
|
|
|
|
Where and how is the variable (or is it a Property ?) 'direction' defined ? Is '_direction' defined anywhere in your code ? best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
It is not defined anywhere in my code. I assume it is an auto generated item from the edmx, but I don't know for certain.
Cheers, --EA
|
|
|
|
|
I was asking about 'direction' and '_direction' used in your code. I'm a little confused by this thread's title which speaks of 'number' and '_number.'
The immediate 'hypothesis' is that '_direction' is a private backing field for a Property somewhere named 'direction;' but, if that's true, how does it get exposed at this point in your code ?
You might clarify in this code example what object 'this' is a reference to ?
Are you dealing with 'black box' code here you can't use the Object Browser in VS Studio on ?
Wish I could help, but my psychic powers are dimmer every day.
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
Fading psychic powers are one of the biggest issues facing our generation today.
Still, in regards to your questions:
1. "this" is in reference to the property class which this is an extension of. It extends the property class from entity framework and is thus related to a sql table which contains address information.
2. I didn't really think that one thing that was interchangable with another required definition. For each attribute of the class there is a matching _field. And now that you mention it I believe you are right that they are autogenerated private backing fields.
public partial class Property
{
public string fullAddress
{
get { return GetFullAddress(this); }
}
private string GetFullAddress(Property property)
{
string tempAddress = property.number.ToString() + ' ';
if (!String.IsNullOrEmpty(property.direction))
tempAddress += property.direction + ' ';
tempAddress += property.street + ' ';
if (!String.IsNullOrEmpty(property.StreetSuffix.name))
tempAddress += property.StreetSuffix.name;
return tempAddress;
}
}
Truth be told this whole thing was more of a curiosity than a question that required anyone tapping in to their well of psychic (and slightly condescending) well.
Thanks for your help, --EA
|
|
|
|
|
Eddie, I apologize if anything in my responses seemed condescending ... I certainly did not have that intent; I hoped you, and any other reader, would experience the 'psychic powers' comment as funny.
As for "our generation:" I bet that I am old ... in years ... enough to be your father
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
That is more than possible, though I do have the hairline and male pattern baldness of a sixty year old man.
Still, the internet has a funny way of making things come across as cynical. Thanks for your response, if I had just remembered the term private backing field it would have helped. So apparently I have the memory of a sixty year old man as well.
Cheers, --EA
|
|
|
|
|
Hi, I'm developing a win32 dll, I'm a c# programmer without a lot of experience in c++. So I decide to do this dll in c#.My dll have to expose a few functions and also has to communicate with a serial port, I resolved pretty well the export functions in the same way as in c++ like win32 API, and about the serial port I will manage it like a safe code object (SerialPort object). But my question is, if one of these functions that the dll export is like "WriteCommMsg(MsgStr * msg)", I don't know were to declare the necesary variables, for example if I'd have to save the last send msg, were this variable would be declared?, I mean, my doubt is what is the lifetime of the variables in a dynamic win32 dll.
For example, try to consider these situation: the user application will call a function of my dll, for example OpenPort()....here my dll has to initialize the port and open it (not only but the basic..), and for doing these create an object of SerialPort....but what happened with the object whe the call to the functions end?....
Hope someone could help me..
thanks
skabo - Robots are a dynamic work of art...
|
|
|
|
|
Please post your questions in one forum only.
|
|
|
|
|
Sorry, but I post it here because I'm evaluating the possibility to use c# or c++, if you see the content of this post is a bit different from the other, but maybe I should have changed the name..sorry
Thx
skabo - Robots are a dynamic work of art...
|
|
|
|
|
The basic issue is the same whichever language you decide to use.
|
|
|
|
|
ok, sorry I´m going to consider for my next post
skabo - Robots are a dynamic work of art...
|
|
|
|
|
In .Net you can use the SerialPort class, you don't have to use unmanaged resources (any more) to talk to external devices.
|
|
|
|
|
Yes I know that, but I'm writing a native win32 dll in c#, and what I wanted to know is where to define the serialport variable, thanks
skabo - Robots are a dynamic work of art...
|
|
|
|
|
Uh, why would you do that? You can't compile C# to a form that doesn't require the .Net Framework (as far as I know), as that's what the language is built for (and it implicitly relies on framework things like the CLR type system, the garbage collector etc).
If you want to write a native DLL, do it in a language that compiles to native code (e.g. C/C++, Delphi/Pascal, etc). If you want to write in C#, make a .Net component (with an exported type library if you need it from native code) and use the managed API to the serial port.
|
|
|
|
|
Hello Everybody,
I have a Blank WPF Window. In which i want to add button at the time of Window load.
How can i add Button in WPF form by using C# Code.
Thanks
If you can think then I Can.
|
|
|
|
|
This would be better asked in the WPF/Silverlight forum.
|
|
|
|
|
Maybe it is an option to add the control in design time and set visibility to false. In the onload event of your window you set thatproperty to visible.
V.
|
|
|
|
|
Hello Everybody,
How can i know that size of Object at the time of declaration of object.
If you can think then I Can.
|
|
|
|