How to Compare value returned by regexp and another string ?
Show older comments
nameF='aa.txt';
cni =regexp (nameF, '.txt', 'split');
I want to compare cni with a String by using strcmp for exemple strcmp(cni,'aa') so I converted its type by using char(cni) since cni is cell but it still returns false even they have the same value. What am I missing here ?
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 3 Apr 2016
Edited: Azzi Abdelmalek
on 3 Apr 2016
nameF='aa.txt';
cni =regexp (nameF, '.txt', 'split')
The result is
cni =
'aa' ''
then
strcmp(cni,'aa')
gives
1 0
What is the problem here?
3 Comments
Zineb EL MORCHID
on 3 Apr 2016
Edited: Azzi Abdelmalek
on 3 Apr 2016
Azzi Abdelmalek
on 3 Apr 2016
cni ={'aa' ''} is a 1x2 cell array
strcmp(cni,'aa') returns two result [1 0]; maybe what you to do is
any(strcmp(cni,'aa'))
Zineb EL MORCHID
on 3 Apr 2016
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!