digitCount property
int
digitCount
Returns the digit count of the String
.
Example
String foo = 'Hello World';
int digitCount = foo.getDigitCount(); // returns 0;
String foo = 'Hello World 123';
int digitCount = foo.getDigitCount(); // returns 3;
Implementation
int get digitCount {
if (this.isBlank) {
return 0;
}
RegExp digitsOnly = RegExp(r'\d');
return digitsOnly.allMatches(this).length;
}