finding a string in a character array

조회 수: 13 (최근 30일)
Ngozika Onunkwo
Ngozika Onunkwo 2016년 3월 19일
편집: Ngozika Onunkwo 2016년 3월 21일
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
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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by