matlab-字符数组与字符比较、字符分类
>> x=['abc','defgh']
x =
abcdefgh
>> x={'abc','defgh'}
x =
??? 'abc'??? 'defgh'
>> y={'111','222'}
y =
??? '111'??? '222'
>> strcat(x,y)
ans =
??? 'abc111'??? 'defgh222'
?
?
?
>> x='aaa'
x =
aaa
>> y='a11'
y =
a11
>> x == y
ans =
???? 1???? 0???? 0
>>
?
?
>> strncmp('aaa','aa11',1)
ans =
???? 1
>> strncmp('aaa','aa11',2)
ans =
???? 1
?
?
>> strcmp('aaa','11')
ans =
???? 0
?
>> strncmp('aaa','aa11',3)
ans =
???? 0
?
?
字符分类:
是否为字母
>> isletter('sssaa11')
ans =
???? 1???? 1???? 1???? 1???? 1???? 0???? 0
是否为空格
>> isspace('s? ssaa11')
ans =
???? 0???? 1???? 1???? 0???? 0???? 0???? 0???? 0???? 0
是否为指定类型
>> isstrprop('s? ssaa11','alpha')
ans =
???? 1???? 0???? 0???? 1???? 1???? 1???? 1???? 0???? 0
>> isstrprop('s? ssaa11','alphanum')
ans =
???? 1???? 0???? 0???? 1???? 1???? 1???? 1???? 1???? 1
?
?Argument C must be a string from the following set:
??? 'alpha'???? : classify S as in the alphabetic letter range
??? 'alphanum'? : classify S as in the alphanumeric range
??? 'cntrl'???? : classify S as in the range of control characters, char(0:20).
??? 'digit'???? : classify S as in the range of numeric digits
??? 'graphic'?? : classify S as in the range of graphic characters. These are
??????????????? all values that represent characters NOT of the set
??????????????? {unassigned, space, line separator, paragraph separator, control
??????????????? characters, Unicode format control characters, private
??????????????? user-defined characters, Unicode surrogate characters, Unicode
??????????????? other characters}.
??? 'lower'???? : classify S as in the range of lowercase letters
??? 'print'???? : classify S as in the range of graphic characters, plus
??????????????? char(32).
??? 'punct'???? : classify S as in the range of punctuation characters
??? 'wspace'??? : classify S as in the range of whitespace characters; this
??????????????? range includes the ANSI C definition of whitespace,
??????????????? {' ','\t','\n','\r','\v','\f'}, in addition to a number of
??????????????? other Unicode characters.
??? 'upper'???? : classify S as in the range of uppercase letters
??? 'xdigit'??? : classify S as in the range of valid hexadecimal digits
?
??? EXAMPLES
?
??? B = isstrprop('abc123efg','alpha') returns B? => [1 1 1 0 0 0 1 1 1]
??? B = isstrprop('abc123efg','digit') returns B? => [0 0 0 1 1 1 0 0 0]
??? B = isstrprop('abc123efg','xdigit') returns B => [1 1 1 1 1 1 1 1 0]