如何计算混合文字/数字字符串中的数字 [英] How can I count the numbers in a string of mixed text/numbers
本文介绍了如何计算混合文字/数字字符串中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我要尝试的是获取一个工作编号(看起来像xxx123432),然后计算条目中的位数,而不是字母.然后,我想将数字的数量分配给一个变量,并使用该变量对作业号进行检查,以确定它们是否为有效格式.
So what I'm trying to do, is take a job number, which looks like this xxx123432, and count the digits in the entry, but not the letters. I want to then assign the number of numbers to a variable, and use that variable to provide a check against the job numbers to determine if they are in a valid format.
我已经找到了执行检查的方法,但是我不知道如何计算工作编号中的数字.
I've already figured out how to perform the check, but I have no clue how to go about counting the numbers in the job number.
非常感谢您的帮助.
推荐答案
使用LINQ:
var count = jobId.Count(x => Char.IsDigit(x));
或
var count = jobId.Count(Char.IsDigit);
这篇关于如何计算混合文字/数字字符串中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文