【发布时间】:2020-10-06 19:44:08
【问题描述】:
我尝试寻找特定的字符组合。组合如下:“文本”:
引号和冒号是其中的一部分。我用 Matlab 的 ismember() 函数尝试了它,但是,它总是单独检查每个字符,我无法搜索整个字符串。下面是一个可重现的例子。
ismember('"text":', '"text": asdf')
% What it returns: 1 1 1 1 1 1 1
% What I want it to return: 1
ismember('"text":', '"teasdfxt": asdf')
% What it returns: 1 1 1 1 1 1 1
% What I want it to return: 0
% I also tried the following options, both did not work
ismember(""text":", '"teasdfxt": asdf')
cellfun(@length, strfind('"text": asdf', '"text":'))
【问题讨论】:
-
如果你有 MATLAB 2016b 或更高版本,也许
contains? -
~isempty(strfind('"text": asdf', '"text":'))怎么样? -
使用 @saastn 的代码我得到了 MATLAB 的建议,将其替换为以下代码:
contains('"text": asdf', '"text":')。这很好用并回答了我的问题。