strcmp(s1,s2):Compare strings 比较字符串s1与s2是否相等,相等返回1;
strncmp(s1,s2,n):Compare first n characters of strings 比较字符串s1与s2前n个字符是否相等,相等返回1;
strcmpi(s1,s2) 与strncmpi(s1,s2,n):忽略大小写字母前提下,比较字符串。
例如
>> ch1='My name is Maxwell';
>> ch2='my name is maxwell';
>> strcmp(ch1,ch2)
ans =
0
>> strcmpi(ch1,ch2)
ans =
1
findstr(s1,s2):返回短字符串在长字符串的开始位置;
strrep(s1,s2,s3):将字符串s1中所有的子字符串s2替换为字符串s3 。
例如:
>> ch='sentence recent gentlemen';
>> findstr(ch,'en')
ans =
2 5 13 18 24
>> strrep(ch,'en','EN')
ans =
sENtENce recENt gENtlemEN