Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,

would somebody please guide me in finding out how to block some punctuation in my code?
I'd like to enter a floating point number and I don't want a comma with the point ".", but ¬
the comma with the real comma like this ",
I have absolutely no idea of how to utilize regular ¬
expression for this.
My code looks something like this:
C#
float value = Convert.ToSingle(Console.Readline());
string rex = @"[0-9],";
// I don't know how to continue from here on

Can somebody please help me?

Stefan
Posted
Updated 16-Nov-12 1:18am
v4

This site http://www.regular-expressions.info/[^] has all kinds off regular expressions, including for floating points www.regular-expressions.info/floatingpoint.html[^].
Just replace the point in the sample with a comma.
 
Share this answer
 
Comments
stefan from germany 17-Nov-12 6:45am    
thx André it help me so much
Try:
[+-]?\d+\,\d+
 
Share this answer
 
Comments
stefan from germany 16-Nov-12 7:07am    
but how to verify it now with my if statement?
OriginalGriff 16-Nov-12 7:15am    
if (Regex.IsMatch("123,456", @"[+-]?\d+\,\d+"))
{
Console.WriteLine("Matched");
}
stefan from germany 17-Nov-12 6:45am    
thx
I just read this yesterday and it makes regular expressions really simple

Learn Regular Expressions (RegEx) with Ease[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900