Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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
Edited 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 at 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 at 16-Nov-12 7:07am
   
but how to verify it now with my if statement?
OriginalGriff at 16-Nov-12 7:15am
   
if (Regex.IsMatch("123,456", @"[+-]?\d+\,\d+"))
{
Console.WriteLine("Matched");
}
stefan from germany at 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
0 Sascha Lefévre 510
1 Sergey Alexandrovich Kryukov 300
2 Abhinav S 255
3 Maciej Los 210
4 Richard Deeming 105
0 Sergey Alexandrovich Kryukov 6,928
1 OriginalGriff 6,381
2 Maciej Los 2,782
3 Abhinav S 2,732
4 Peter Leow 2,694


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2015
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