我试图让一个程序的子版本,而这个返回以下字符串Release 4.2.3 of programX
有时也:Release 4.3 of programX
。我想检查字符串是否包含3个或更多的小数位(如4.3.2)。
我找到了有答案的问题,但不是C#的问题,这在C#中可能吗,如果可以,最好的方法是什么?
使用linq。
bool more3dec = input.Count(c => c == '.') >= 2;
或正则表达式。(仅检查数字部分内的点)
bool more3dec = Regex.IsMatch(input, @"\d+\.\d+\.\d+");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句