finding a string in a character array
13 次查看(过去 30 天)
显示 更早的评论
Good day people.please I need your help.
If a user inputs a character array of strings in the edit box,and he clicks on the pushbutton,I need a code that will check if the input:
has the letter A :disp'it is upi dialect'.
has the letter R :disp'it is iri dialect'.
has the letter Y and E :it is ibakwa dialect'
contains a word that ends with letter S :it is udi dialect'
note the letters are case insensitive
回答(1 个)
Jan
2016-3-19
Add in the callback of the edit field:
Str = get(EditH, 'String');
% Is it a multi-line edit field? Then convert it to a string at first:
if iscell(Str)
Str = sprintf('%s\n', Str{:});
end
lowStr = lower(Str);
if any(strfind(lowStr, 'a'))
disp('it is upi dialect');
elseif any(strfind(lowStr, 'r'))
disp('it is iri dialect');
elseif any(strfind(lowStr, 'y')) || any(strfind(lowStr, 'e'))
disp('it is ibakwa dialect');
elseif any(lowStr, 's\>') % contains a word that ends with letter S:
disp('it is udi dialect');
else
disp('???');
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!