matlab中提供了几个函数用于字符串的搜索和替换:
strrep函数对字符串进行搜索和替换操作;
findstr函数把子字符串的起始位置返回到所在母字符的位置;
strtok函数在输入字符串中第一个发现间隔符时返回间隔符前面的字符;可用该函数将句子分成单词;
strmatch函数在字符数组或字符串单元数组的整个行中进行查找,看有没有以给定字符序列打头的字符串,它返回以该字符串打头的行号。
%查找替换%
>> label=’honkin is a bloger’;
>>newlabel=strrep(label,’bloger’,'blogger’) ;
newlabel =
honkin is a blogger
%用findstr查找子字符串的位置%
childstr=findstr(’is’,newlabel)
childstr =
8
%将句子分成单词%
all_words=”;
newlabel=’honkin is a blogger!’
while(any(newlabel))
[chopped,newlabel]=strtok(newlabel);
all_words=strvcat(all_words,chopped);
end
newlabel =
honkin is a blogger!
>> all_words
all_words =
honkin
is
a
blogger!
归档在: 分析软件 — honkin @ 9:43 下午

呃……有点高深
[Reply]
麦小田 —— 4月 29, 2008 @11:12 下午
我也是刚刚学习,呵呵
[Reply]
honkin —— 4月 29, 2008 @11:22 下午