isstrprop
确定字符串是否为指定类别
Syntax
tf = isstrprop(str,类别)
tf = isstrprop(str,类别,'ForceCellOutput',tf)
描述
determines if elements of input text are of the specified category, such as letters, numbers, or whitespace. For example,TF
= isstrprop(str
,类别
)isstrprop('abc123','alpha')
返回一个1
-经过-6
logical array,[1 1 1 0 0 0]
,表明前三个字符是字母。
如果
str
是字符数组,字符串标量或数字数组,然后isstrprop
返回一个logical array.如果
str
is a cell array of character vectors or a string array, thenisstrprop
返回一个逻辑向量的细胞阵列.
例子
Determine Which Characters Are Letters
创建一个字符向量并确定哪些字符是字母。
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 inchr
usingTF
.
idx = find(tf)
idx =5 6 7 8 9 11 12 13 14 15 16
chr(idx)
ans ='maplestreet'
确定字符串数组中的字符类型
创建字符串数组。然后确定哪个字符属于各种类别isstrprop
function.
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 thestring
function.
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
Determine Types of Characters in Cell Array
创建一个字符向量的单元格数组。确定哪些字符是空格字符。
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逻辑}
查找标点符号的索引chr
usingTF{1}
.
查找(tf {1})
ans =8 17 41
Determine Character Types in Numeric Array
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
isstrprop
identifies all the numbers as character codes for letters. Convert the numbers to their corresponding characters with thechar
function.
c = char(x)
c ='matlab'
Input Arguments
str
—输入数组
字符串数组|字符阵列|细胞array of character vectors|numeric array
输入数组,指定为字符串数组,字符数组,字符向量的单元格数组或数字数组。
如果str
is a numeric array, thenisstrprop
treats the numbers as Unicode®角色代码。如果数字是双重或单精度的浮点数,则isstrprop
rounds 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
类别
—角色类别
'α'
|'alphanum'
|'cntrl'
|'digit'
|'graphic'
| ...
角色类别, specified as a character vector or string scalar.isstrprop
classifies the characters instr
according to categories defined by the Unicode standard.
类别 |
描述 |
---|---|
|
Letters. |
|
Letters or numeric digits. |
|
控制字符(例如, |
|
Numeric digits. |
|
图形字符。
|
|
小写字母。 |
|
Graphic characters, plus |
|
标点字符。 |
|
空间字符。此范围包括ANSI®C的定义,空格, |
|
Uppercase letters. |
|
有效的十六进制数字。 |
tf
—对或错
0
(default) |1
对或错, specified as1
或者0
.
Output Arguments
TF
— True or false
逻辑数组|逻辑向量的细胞阵列
真或错误,作为逻辑向量的逻辑数组或单元格数组返回。
如果
str
is a character vector, string scalar, or numeric array, thenTF
is a logical array indicating which characters belong to the specified category.如果
str
is a cell array of character vectors or a string array, thenTF
是一个单元格数组。对于每个元素str
,相应的细胞TF
包含一个逻辑向量,指示该元素中的哪些字符属于指定类别。
提示
Whitespace characters for which thewspace
option returns真的
除其他一些Unicode字符外,还包括标签,线馈电,垂直选项卡,形式馈电,托架返回和空间。查看所有字符wspace
option returns真的
,输入以下命令,然后在Unicode参考中查找返回的十进制代码:
寻找(isstrprop(char(1):char(intmax('uint16')),'wspace'))
Extended Capabilities
C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。
用法注释和限制:
输入数组必须指定为字符数组或整数数组。
输入值必须在0-127范围内。
在R2006a之前引入
matlab命令
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
美洲
- AméricaLatina(Español)
- Canada(英语)
- 美国(英语)
欧洲
- Belgium(英语)
- 丹麦(英语)
- Deutschland(德意志)
- españa(Español)
- Finland(英语)
- 法国(Français)
- 爱尔兰(英语)
- 意大利(Italiano)
- Luxembourg(英语)
- Netherlands(英语)
- 挪威(英语)
- Österreich(德意志)
- Portugal(英语)
- Sweden(英语)
- 瑞士
- 英国(英语)