AI-Algorithms

在Matlab中,这几个函数区分如下:

(以下默认S1和S2是字符串,同样也适用于cell细胞类型数据,也就是循环对cell中每个元素分别判断即可。)

findstr(S1,S2):寻找是否有S1和S2之间的匹配,真返回1,假返回0,双向;

例:          s = \'How much wood would a woodchuck chuck?\';

                findstr(s,\'a\')    returns  21

                findstr(\'a\',s)    returns  21

                findstr(s,\'wood\') returns  [10 23]

                findstr(s,\'Wood\') returns  []

                findstr(s,\' \')    returns  [4 9 14 20 22 32]

strfind(S1,S2):寻找S2是否匹配S1,和上面的唯一区别就是这个是单向的。请注意唯一的区别在例子中红字部分。

 例:       s = \'How much wood would a woodchuck chuck?\';

               strfind(s,\'a\')    returns  21

               strfind(\'a\',s)    returns  []

               strfind(s,\'wood\') returns  [10 23]

               strfind(s,\'Wood\') returns  []

               strfind(s,\' \')    returns  [4 9 14 20 22 32]

strcmp(S1,S2):寻找S1和S2是否完全匹配,S1和S2没有顺序的区分。

例:       s= \'wooden\';

              strcmp(s,\'wood\')    returns 0

              strcmp(s,\'wooden\')    returns 1

              strcmp(\'wooden\',s)    returns 1

strcnmp(S1,S2,n):寻找S1和S2的前n个字符是否完全匹配,S1和S2没有顺序的区分。

例:       s= \'wooden\';

             strncmp(s,\'wood\',4)    returns 1

             strncmp(s,\'wood\',5)    returns 0

              strncmp(s,\'wooden\',4)    returns 1

              strncmp(\'wooden\',s,4)    returns 1

strcmpi(S1,S2)与strncmpi(S1,S2,n)与上面分别对应的strcmp(S1,S2)与strncmp(S1,S2,n)完全相同,唯一的区分是匹配时不区分大小写。

参考文献:

<http://www.mathworks.com/matlabcentral/newsreader/view_thread/257590>

<http://www.mathworks.com/matlabcentral/newsreader/view_thread/145799>

<http://www.mathworks.com/matlabcentral/newsreader/view_thread/145799>

<http://www.mathworks.de/matlabcentral/newsreader/view_thread/294626>

 

源文档 <http://blog.163.com/6_mao/blog/static/63271315201110203738923/>

分类:

技术点:

相关文章:

  • 2021-09-20
  • 2021-10-17
  • 2022-02-09
  • 2022-12-23
  • 2021-11-29
  • 2021-06-06
  • 2021-06-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2021-07-29
相关资源
相似解决方案