1.char 函数将数值转为字符串
>> a=120
a =
120
>> class(a)
ans =
'double'
>> size(a)
ans =
1 1
>> a=char('Hellow','World')
a =
2×6 char 数组
'Hellow'
'World '
>> class(a)
ans =
'char'
>> size(a)
ans =
2 6
2.double 函数将字符串转为数值
>> a=double(a)
a =
72 101 108 108 111 119
87 111 114 108 100 32
>> class(a)
ans =
'double'
>> size(a)
ans =
2 6
3.blanks 函数创建空字符串
>> a=blanks(8)
a =
' '
4.deblank 函数去掉字符串末尾空格
>> a='abc '
a =
'abc '
>> deblank(a)
ans =
'abc'
5.ischar 函数判断变量是否为字符类型
>> a='1'
a =
'1'
>> ischar(a)
ans =
logical
1
>> b=1
b =
1
>> ischar(b)
ans =
logical
0
6.strcat 函数水平组合字符串
>> a='hello'
a =
'hello'
>> b='world'
b =
'world'
>> c=strcat(a,b)
c =
'helloworld'
7.strvcat 函数创建字符矩阵
>> a='hello'
a =
'hello'
>> b='world'
b =
'world'
>> d=strvcat(a,b)
d =
2×5 char 数组
'hello'
'world'
8.strcmp 函数比较字符串
>> a='abc'
a =
'abc'
>> b='abc'
b =
'abc'
>> strcmp(a,b)
ans =
logical
1
9.strncmp 函数比较字符串前n个字符
>> a='abc'
a =
'abc'
>> b='abcd'
b =
'abcd'
>> strncmp(a,b,3)
ans =
logical
1
10.findstr 函数在长字符串中查找短字符串索引
>> a='abcd'
a =
'abcd'
>> b='bc'
b =
'bc'
>> c=findstr(a,b)
c =
2
11.strfind 函数在第一个字符串中查找第二个字符串的索引
>> a='abcd'
a =
'abcd'
>> b='bc'
b =
'bc'
>> c=findstr(a,b)
c =
2
>> d=findstr(b,a)
d =
2
12.strjust 函数对齐排列字符串
>> a='hello'
a =
'hello'
>> b='world'
b =
'world'
>> c=strvcat(a,b)
c =
2×5 char 数组
'hello'
'world'
>> d=strjust(c)
d =
2×5 char 数组
'hello'
'world'
13.strrep 函数替换字符串中的字串
>> s1='hallo world'
s1 =
'hallo world'
>> s2=strrep(s1,'hallow','hello')
s2 =
'hallo world'
14.strmatch 函数查询匹配的字符串
>> s=strmatch('ab',strvcat('abandon','absorb','about'))
s =
1
2
3
15.strcmpi 函数查询字符串是否匹配(忽略大小写)
>> a=strcmpi('abc','ABC')
a =
logical
1
16.strncmpi 函数查询字符串前n个字符是否匹配(忽略大小写)
>> a=strncmpi('abcde','AbCef',3)
a =
logical
1
17.upper 函数将字符串转为全部大写
>> s1='Hello World'
s1 =
'Hello World'
>> s2=upper(s1)
s2 =
'HELLO WORLD'
18.lower 函数将字符串转为全部小写
>> s1='Hello World'
s1 =
'Hello World'
>> s3=lower(s1)
s3 =
'hello world'