您的位置:首页 > 编程语言 > MATLAB

matlab 字符串处理

2016-05-08 23:25 597 查看

0. 字符串比较

strcmp()

strcmpi():大小写不敏感,case insensitive;

1. deblank

Remove trailing whitespace from end of character array. (删除序列尾部(注意仅仅是尾部,不包括头部的空格)的空格)。

2. 字符串切割(split)

使用正则表达式:

>> str = 'hello world hello China';
>> splited = regexp(str, ' ', 'split');
>> splited
splited =
'hello'    'world'    'hello'    'China'


注意
regexp(str, ' ', 'split')
得到的是元组类型。

3. strfind():返回元素的下标

>> strfind('hello|world', '|')
6


4. char ⇔ ASCII

(1)ASCII ⇒ char

>> char([97, 98, 99])
ans =

abc


(2)char ⇒ ASCII

>> abs('abc')
ans =

97    98    99


5. 字符串的拼接

字符串(str1、str2)的拼接使用 [str1, str2] 或 [str1 str2]。

注意,str1 + str2 所做的动作就不是拼接了,而是首先转换为 ascii 码类型,再进行相加的操作,这就要求两串的长度必须相等,

>> str1 = 'hello'; str2 = 'world';
>> str1 + str2
ans =

223   212   222   216   211
>> abs(str1) + abs(str2)
ans =

223   212   222   216   211
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: