zoukankan      html  css  js  c++  java
  • matlab中findstr,strfind,strcmp,strncmp区别与联系

    在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/>

  • 相关阅读:
    Vue入门
    吃透SprinngBoot
    SSM整合详解
    Linux查找端口并关闭
    接入腾讯云的OCR识别身份证信息
    IDEA 快捷键《宋红康版》
    Mysql详解
    docker常见命令
    SpringBoot集成Redis
    使用mybatis出现异常
  • 原文地址:https://www.cnblogs.com/AI-Algorithms/p/3670848.html
Copyright © 2011-2022 走看看