contains

语法

``TF = contains(str,pat)``
``TF = contains(str,pat,'IgnoreCase',true)``

说明

`如果 `str` 包含指定的模式，`TF = contains(str,pat)` 将返回 `1` (`true`)，否则返回 `0` (`false`)。如果 `pat` 是一个包含多个模式的数组，则当 `contains` 在 `str` 中发现任何 `pat` 元素时，它将返回 `1`。`

``TF = contains(str,pat,'IgnoreCase',true)` 在确定 `str` 是否包含 `pat` 时将忽略大小写。`

示例

`str = ["Mary Ann Jones","Paul Jay Burns","John Paul Smith"]`
```str = 1x3 string "Mary Ann Jones" "Paul Jay Burns" "John Paul Smith" ```

```pat = "Paul"; TF = contains(str,pat)```
```TF = 1x3 logical array 0 1 1 ```

`str(TF)`
```ans = 1x2 string "Paul Jay Burns" "John Paul Smith" ```

`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`
```pat = pattern Matching: digitsPattern ```

`TF = contains(str,pat)`
```TF = 1x3 logical array 1 0 1 ```
`str(TF)`
```ans = 1x2 string "221B Baker St." "4059 Mt Lee Dr." ```

`pat = digitsPattern + lettersPattern(1)`
```pat = pattern Matching: digitsPattern + lettersPattern(1) ```
```TF = contains(str,pat); str(TF)```
```ans = "221B Baker St." ```

`str = ["Mary Ann Jones","Christopher Matthew Burns","John Paul Smith"]`
```str = 1x3 string "Mary Ann Jones" "Christopher Matth..." "John Paul Smith" ```

```pat = ["Ann","Paul"]; TF = contains(str,pat)```
```TF = 1x3 logical array 1 0 1 ```

`str(TF)`
```ans = 1x2 string "Mary Ann Jones" "John Paul Smith" ```

`str = ["Anne","Elizabeth","Marianne","Tracy"]`
```str = 1x4 string "Anne" "Elizabeth" "Marianne" "Tracy" ```
```pat = "anne"; TF = contains(str,pat,'IgnoreCase',true)```
```TF = 1x4 logical array 1 0 1 0 ```

`str(TF)`
```ans = 1x2 string "Anne" "Marianne" ```

```chr = 'peppers, onions, and mushrooms'; TF = contains(chr,'onion')```
```TF = logical 1 ```
`TF = contains(chr,'pineapples')`
```TF = logical 0 ```

输入参数

• 字符串数组

• 字符向量

• 字符向量元胞数组

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