Click here to Skip to main content
13,255,340 members (46,168 online)
Rate this:
 
Please Sign up or sign in to vote.
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:
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 16-Nov-12 1:53am
Updated 16-Nov-12 2:18am
v4
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
stefan from germany 17-Nov-12 6:45am
   
thx André it help me so much
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try:
[+-]?\d+\,\d+
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

I just read this yesterday and it makes regular expressions really simple

Learn Regular Expressions (RegEx) with Ease[^]
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100