regex
-
public bool IsInteger(string sender) { Regex regex = new Regex("[^0-9]"); return !regex.IsMatch(sender); } hi i get confused with the code above... why when i put e.g. 333 as the sender.. regex.IsMatch(sender); this is returning false ?? and i must put a ! there ?? my logic is .. when regex[^0-9] = integer then it must return true... pls advice
-
public bool IsInteger(string sender) { Regex regex = new Regex("[^0-9]"); return !regex.IsMatch(sender); } hi i get confused with the code above... why when i put e.g. 333 as the sender.. regex.IsMatch(sender); this is returning false ?? and i must put a ! there ?? my logic is .. when regex[^0-9] = integer then it must return true... pls advice
public bool IsInteger(string sender)
{
return Regex.IsMatch(sender, @"^[\d]*$", RegexOptions.None);
}How about this ? BTW, easy solution is
int.TryParse()
than this.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
public bool IsInteger(string sender) { Regex regex = new Regex("[^0-9]"); return !regex.IsMatch(sender); } hi i get confused with the code above... why when i put e.g. 333 as the sender.. regex.IsMatch(sender); this is returning false ?? and i must put a ! there ?? my logic is .. when regex[^0-9] = integer then it must return true... pls advice
-
public bool IsInteger(string sender) { Regex regex = new Regex("[^0-9]"); return !regex.IsMatch(sender); } hi i get confused with the code above... why when i put e.g. 333 as the sender.. regex.IsMatch(sender); this is returning false ?? and i must put a ! there ?? my logic is .. when regex[^0-9] = integer then it must return true... pls advice
Maybe OT, but why are you not using bool int.TryParse(string,out int) ?