Click here to Skip to main content
11,707,254 members (64,254 online)
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 0:53am
Edited 16-Nov-12 1: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 Sergey Alexandrovich Kryukov 145
1 OriginalGriff 141
2 chainerlt 110
3 ppolymorphe 104
4 Mika Wendelius 90
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,806
4 Mika Wendelius 3,706


Advertise | Privacy | Mobile
Web04 | 2.8.150819.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