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 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 3

I just read this yesterday and it makes regular expressions really simple
 
Learn Regular Expressions (RegEx) with Ease[^]
  Permalink  
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

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 540
1 CPallini 290
2 OriginalGriff 265
3 ChauhanAjay 124
4 George Jonsson 120
0 OriginalGriff 6,474
1 Sergey Alexandrovich Kryukov 6,190
2 CPallini 5,180
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2014
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