# count

## 语法

``A = count(str,pat)``
``A = count(str,pat,'IgnoreCase',true)``

## 说明

``A = count(str,pat)` 返回 `pat` 在 `str` 中的出现次数。如果 `pat` 是包含多个模式的数组，则 `count` 返回 `pat` 的所有元素在 `str` 中出现的总次数。`count` 从左到右依次匹配 `pat` 的元素。`str` 中的文本段只能匹配一次。`

``A = count(str,pat,'IgnoreCase',true)` 在统计 `pat` 的出现次数时，将忽略大小写。`

## 示例

`str = "paired with red shoes"`
```str = "paired with red shoes" ```

`A = count(str,"red")`
```A = 2 ```

```str = ["red green red red blue blue green"; "green red blue green green blue"]```
```str = 2x1 string "red green red red blue blue green" "green red blue green green blue" ```

`A = count(str,"red")`
```A = 2×1 3 1 ```

`str = ["221B Baker St.","Tour Eiffel Champ de Mars","4059 Mt Lee Dr."]`
```str = 1x3 string "221B Baker St." "Tour Eiffel Champ..." "4059 Mt Lee Dr." ```

`pat = digitsPattern(1)`
```pat = pattern Matching: digitsPattern(1) ```

`A = count(str,pat)`
```A = 1×3 3 0 4 ```

`A = count(str,lettersPattern(1))`
```A = 1×3 8 21 7 ```

```pat = digitsPattern + lettersPattern(1); A = count(str,pat)```
```A = 1×3 1 0 0 ```

```str = ["red green blue"; "green red blue green blue"]```
```str = 2x1 string "red green blue" "green red blue green blue" ```

`count` 为第一个字符串返回 2，因为 `red``blue` 各出现一次。`count` 为第二个字符串返回 3，因为 `red` 出现一次，`blue` 出现两次。

`A = count(str,["red","blue"])`
```A = 2×1 2 3 ```

`str = ["Edgar Allan Poe";"Louisa May Alcott"]`
```str = 2x1 string "Edgar Allan Poe" "Louisa May Alcott" ```
`A = count(str,'E','IgnoreCase',true)`
```A = 2×1 2 0 ```

`chr = 'alphabetical'`
```chr = 'alphabetical' ```
`A = count(chr,'al')`
```A = 2 ```

## 输入参数

• 字符串数组

• 字符向量

• 字符向量元胞数组

• `pattern` 数组（自 R2020b 开始提供）