繁体   English   中英

使用 Matlab 查找字符串中包含的 substring

[英]Find which substring is contained in string with Matlab

我有一个名为“条件”的 char 变量。 该变量的内容类似于:“21331-54-task-5da1-6256853-35-1-3.mp4”。

我需要确定名称中包含以下哪个字符:25、35、45。我尝试使用 contains(),但这仅告诉我其中一个是否包含在条件中。 它没有告诉我包含哪一个。

我也试过:

strToFind = {'25', '35', '45'};

pos = strfind(strToFind,条件)

但它给了我以下结果:

位置 =

1×3 单元阵列

{0×0 double} {0×0 double} {0×0 double}

关于如何解决这个问题的任何建议? 先感谢您

~cellfun(@isempty, regexp(condition, strToFind, 'once'))

将给出一个与strToFind strToFind的每个字符串是否存在于condition中。

你也可以使用

cellfun(@(x) contains(condition, x), strToFind)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM