Since R2020b
Create a string array that contains addresses.
str = 1x3 string
"221B Baker St." "Tour Eiffel Champ..." "4059 Mt Lee Dr."
To count the digits in each address, first create a pattern that matches a single digit. The number of times this pattern occurs in a string equals the number of digits in the string.
Create the pattern by calling the digitsPattern
function with 1
as the input argument. When you do this, it matches a single digit (such as 2
) instead of an arbitrary sequence of digits (such as 221
or 4059
).
pat = pattern
Matching:
digitsPattern(1)
Then call the count
function with str
and pat
as inputs.
Similarly, you can count the number of letters (not including digits, spaces, or punctuations marks) by using the pattern created by lettersPattern(1)
.
Count sequences consisting of one or more digits and then one letter. You can build more complex patterns by combining simple patterns. In this case, digitsPattern + lettersPattern(1)
matches 221B
.
For a list of functions that create pattern objects, see pattern
.