Documentation

isstrprop

确定字符串是否为指定类别

Syntax

tf = isstrprop(str,类别)
tf = isstrprop(str,类别,'ForceCellOutput',tf)

描述

example

TF= isstrprop(str,类别)determines if elements of input text are of the specified category, such as letters, numbers, or whitespace. For example,isstrprop('abc123','alpha')返回一个1-经过-6logical array,[1 1 1 0 0 0],表明前三个字符是字母。

  • 如果str是字符数组,字符串标量或数字数组,然后isstrprop返回一个logical array.

  • 如果stris a cell array of character vectors or a string array, thenisstrprop返回一个逻辑向量的细胞阵列.

example

TF= isstrprop(str,类别,'ForceCellOutput',tf), wheretfis1(真的), returnsTFas a cell array even whenstris a character array, string scalar, or numeric array. The default fortfis0(false).

例子

全部折叠

创建一个字符向量并确定哪些字符是字母。

chr ='123 Maple Street'
chr = '123 Maple Street'
TF = isstrprop(chr,'α')
TF =1x16 logical array0 0 0 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1

Find indices for the letters inchrusingTF.

idx = find(tf)
idx =5 6 7 8 9 11 12 13 14 15 16
chr(idx)
ans ='maplestreet'

创建字符串数组。然后确定哪个字符属于各种类别isstrpropfunction.

Create a string scalar and determine which of its characters are numeric digits. Starting in R2017a, you can create strings using double quotes instead of thestringfunction.

str ="123 Maple Street"
str = "123 Maple Street"
tf = isstrprop(str,'digit')
TF = 1x16 logical array 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0

Create a nonscalar string array. Determine which characters in each string are whitespace characters.isstrprop返回一个细胞array in which each cell contains results for a string instr.

str = [“ 123 Maple St.”;“ 456 Oak St.”]
str = 2x1字符串阵列“ 123 Maple St.”“ 456 Oak St.”
tf = isstrprop(str,“ WSPACE”)
tf = 2x1单元格数组{1x13逻辑} {1x11逻辑}

要显示第二个字符串的结果,str(2),索引TF{2}.

TF{2}
ans = 1x11 logical array 0 0 0 1 0 0 0 1 0 0 0

创建一个字符向量的单元格数组。确定哪些字符是空格字符。

C ={'123 Maple St.';'456 Oak St.'}
C =2x1 cell array{'123 Maple St.'} {'456 Oak St.'}
TF = isstrprop(C,“ WSPACE”)
TF =2x1 cell array{1x13 logical} {1x11 logical}

Find the punctuation characters in a character vector.isstrprop返回一个logical vector indicating which characters belong to that category. Forceisstrprop要返回单元格中的逻辑向量。

chr ='A horse! A horse! My kingdom for a horse!'
chr = 'A horse! A horse! My kingdom for a horse!'
TF = isstrprop(chr,'punct',“ forceleloutput”,true)
TF =1x1单元格数组{1x41逻辑}

查找标点符号的索引chrusingTF{1}.

查找(tf {1})
ans =8 17 41

Create a numeric array. Determine which numbers correspond to character codes for letters.

X = [77 65 84 76 65 66]
X =77 65 84 76 65 66
TF = isstrprop(X,'α')
TF =1x6逻辑数组1 1 1 1 1 1

isstrpropidentifies all the numbers as character codes for letters. Convert the numbers to their corresponding characters with thecharfunction.

c = char(x)
c ='matlab'

Input Arguments

全部折叠

输入数组,指定为字符串数组,字符数组,字符向量的单元格数组或数字数组。

如果stris a numeric array, thenisstrproptreats the numbers as Unicode®角色代码。如果数字是双重或单精度的浮点数,则isstrproprounds them to the nearest integer values before interpreting them as character codes.

Data Types:string|char|细胞|double|single|int8|INT16|INT32|int64|uint8|UINT16|uint32|uint64

角色类别, specified as a character vector or string scalar.isstrpropclassifies the characters instraccording to categories defined by the Unicode standard.

类别

描述

alpha

Letters.

alphanum

Letters or numeric digits.

cntrl

控制字符(例如,char(0:20)).

digit

Numeric digits.

graphic

图形字符。isstrproptreats all Unicode characters as graphic characters, except for the following:

  • 未分配的字符

  • Whitespace characters

  • The line separator

  • 段落分隔符

  • Control characters

  • 私有用户定义的字符

  • Surrogate characters

lower

小写字母。

print

Graphic characters, pluschar(32).

标点字符。

wspace

空间字符。此范围包括ANSI®C的定义,空格,{'','\ t','\ n','\ r','\ v','\ f'},除了其他一些Unicode字符。

upper

Uppercase letters.

xDigit

有效的十六进制数字。

对或错, specified as1或者0.

Output Arguments

全部折叠

真或错误,作为逻辑向量的逻辑数组或单元格数组返回。

  • 如果stris a character vector, string scalar, or numeric array, thenTFis a logical array indicating which characters belong to the specified category.

  • 如果stris a cell array of character vectors or a string array, thenTF是一个单元格数组。对于每个元素str,相应的细胞TF包含一个逻辑向量,指示该元素中的哪些字符属于指定类别。

提示

Whitespace characters for which thewspaceoption returns真的除其他一些Unicode字符外,还包括标签,线馈电,垂直选项卡,形式馈电,托架返回和空间。查看所有字符wspaceoption returns真的,输入以下命令,然后在Unicode参考中查找返回的十进制代码:

寻找(isstrprop(char(1):char(intmax('uint16')),'wspace'))

Extended Capabilities

在R2006a之前引入

这个话题有帮助吗?