|
It is not validating "100."
|
|
|
|
|
I hope you want regex is based on some sense.
Are you sure "100." is a valid decimal or It has any meaning ?
If you want to pass 100. any way then use "^\d+\.{0,1}(?:\d+)?$ ".
|
|
|
|
|
this might help
\d+[.]{0,1}\d*
|
|
|
|
|
Have you checked it by value 100/12 , That's the problem of OP.
In your case it will return 2 Matches, Just need to wrap Regex in ^Regex$ to solve the issue.
|
|
|
|
|
Below one solved the problem. Thanks alot Hiren and Ravi
"^\d+[.]{0,1}\d*$"
|
|
|
|
|
HaroldVish wrote: Thanks alot Hiren
You're welcome, You can always rate the answer which helped you, That encourages the person to give answer.
|
|
|
|
|
its validating "50-99"
But it shouldn't
|
|
|
|
|
You should have asked this in the regular expression forum. It needs more traffic.
|
|
|
|
|
Ok, I didn't notice Regular expression has separate forum
|
|
|
|
|
Nobody does. It's why I was trying to boost the traffic to it and not do the usual stamp down hard on the poster thing.
|
|
|
|
|
Hi,
I am trying to do a search in VSTO Word add-in 2007 from background thread or background worker. I'm getting an exception "External component has thrown an exception".
Range range = document.Content;
Find findSpell = range.Find;
findSpell.Text = "test";
It works when I invoke it directly from the same thread.
Is there any possibility to do this in background thread because this is lengthy operation?
PS
I'm trying to achieve similar functionality as spelling and grammar
|
|
|
|
|
How Can I Upload and Resize Image in PHP?
|
|
|
|
|
You could start by READING THE NAME OF THE FORUM!
Sorry about the shouting, but it's been one of those days - and it's only 09:15...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Come on, take it easy, it's friday. Hear me? TAKE IT EASY
Edit: Oh, come on, guys. I was just kidding... It's friday...
modified on Friday, December 17, 2010 11:54 AM
|
|
|
|
|
Hello All,
I found the need to use enumeration as indexer to simplify coding and just realized, I created bugs all over.
The situation is like this...
using System;
using System.Collections.ObjectModel;
namespace Demo
{
class Program
{
public enum AFormatType
{
None = 0,
ItemA = 1,
ItemB = 2,
ItemC = 3,
ItemD = 4,
}
public class AFormat
{
AFormatType _type;
public AFormat(AFormatType type) { _type = type; }
public AFormatType FormatType
{
get { return _type; }
}
}
public class AFormatCollection : Collection<AFormat>
{
public AFormat this[AFormatType type]
{
get
{
for (int i = 0; i < this.Count; i++)
{
AFormat format = base[i];
if (format.FormatType == type)
{
return format;
}
}
return null;
}
}
}
static void Main(string[] args)
{
AFormatCollection collFormats = new AFormatCollection();
collFormats.Add(new AFormat(AFormatType.ItemA));
collFormats.Add(new AFormat(AFormatType.ItemB));
collFormats.Add(new AFormat(AFormatType.ItemC));
collFormats.Add(new AFormat(AFormatType.ItemD));
AFormat testFormat = collFormats[0];
}
}
}
I was surprised to find that the testFormat is null . Is the C# enum nothing better than the C++? If the compiler considers this to be another this[int index] , why did this compile successfully?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
modified on Saturday, December 18, 2010 1:24 AM
|
|
|
|
|
0 is always legal when an enum is expected
From the C# language spec:
13.1.3 Implicit enumeration conversions
An implicit enumeration conversion permits the decimal-integer-literal 0 to be converted to any enum-type.
|
|
|
|
|
harold aptroot wrote: 0 is always legal when an enum is expected
I think that explains the issue, since the output of the ff. are the same: ItemC .
(NOTE: reversed the content)
static void Main(string[] args)
{
AFormatCollection collFormats = new AFormatCollection();
collFormats.Add(new AFormat(AFormatType.ItemD));
collFormats.Add(new AFormat(AFormatType.ItemC));
collFormats.Add(new AFormat(AFormatType.ItemA));
collFormats.Add(new AFormat(AFormatType.ItemB));
testFormat = collFormats[1];
if (testFormat != null)
{
Console.WriteLine(testFormat.FormatType.ToString());
}
testFormat = collFormats[AFormatType.ItemC];
if (testFormat != null)
{
Console.WriteLine(testFormat.FormatType.ToString());
}
}
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
You start with adding ItemA..ItemD to the list. Then you loop through the list, looking for item "None". That's done here;
for (int i = 0; i < this.Count; i++)
{
AFormat format = this[i];
if (format.FormatType == type)
{
return format;
}
}
return null; The first time it goes through that loop, format.FormatType = "ItemA", and type == "None". It'll continue with the loop, check "ItemD", and move on to the "return null" statement.
Try this code;
collFormats.Add(new AFormat(AFormatType.ItemA));
collFormats.Add(new AFormat(AFormatType.ItemB));
collFormats.Add(new AFormat(AFormatType.ItemC));
collFormats.Add(new AFormat(AFormatType.ItemD));
AFormat testFormat = collFormats[0];
collFormats.Add(new AFormat(AFormatType.None));
testFormat = collFormats[0];
Enjoy
I are Troll
|
|
|
|
|
I think you have missed the main point.
AFormatCollection : Collection<AFormat> is a collection and therefore supports the this[int index] ,
so the AFormat testFormat = collFormats[0]; is asking for the zero-indexed item.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
modified on Friday, December 17, 2010 6:03 AM
|
|
|
|
|
Paul Selormey wrote: so the AFormat testFormat = collFormats[0]; is asking for the zero-indexed item.
Ask your debugger;
for (int i = 0; i < this.Count; i++)
{
AFormat format = base[i];
if (format.FormatType == type)
{
return format;
}
}
return null;
Your indexer-implementation doesn't return anything based on index, it's returning the item that has the specified enumvalue. The debugger will loop through the collection, compare the type parameter from your indexer to the FormatType property. Since there's no item in the collection with a enumvalue None , null is returned.
It's not going to take the 0 as a hint that it should use the inherited indexer, it'll simply convert your 0 into the enums value for (int)0 and use the indexer that's specified for the enum.
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: It's not going to take the 0 as a hint that it should use the inherited indexer, it'll simply convert your 0 into the enums value for (int)0 and use the indexer that's specified for the enum.
In which case it should also convert 1 to the enums value for (int)1 , right? Try it.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
No, see my earlier comment. The conversion from int to enum is only implicit when the int is zero.
|
|
|
|
|
harold aptroot wrote: No, see my earlier comment.
Right, I am only implying that from his statements.
I have verified your earlier comment and it is valid, the only valid explanation to this issue.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul Selormey wrote: In which case it should also convert 1 to the enums value for (int)1, right? Try it.
You're right, the framework took the correct indexer
I are Troll
|
|
|
|
|
As I know from OOP theory, the purpose of private Properties is to have the variables of an object protected from other classes, that could accidentaly change their value, thus provoking complications in a software. Am I correct till here?
Then I started to read C# and I found out that variables are called fields and they are also usually private. But there are also Properties with set and get which are used to change variables' (fields') values.
For instance:
I have a variable category in a class Myclass.
To follow strict C# grammar I write
private int cat;
and then I create a property with set and get
public int Category<br />
{<br />
get { return cat; }<br />
<br />
set { cat = value; }<br />
}
Therefore I can access the property from any other class using
Myobject.Category = 5
And here comes the question: why use such a complicated way? Why not use directly a public cat field? After all, cat is still not protected since I can directly change Category instead.
Thanks in advance for any reply.
|
|
|
|