finding a string in a character array

13 views (last 30 days)
Ngozika Onunkwo
Ngozika Onunkwo on 19 Mar 2016
Edited: Ngozika Onunkwo on 21 Mar 2016
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

Answers (1)

Jan
Jan on 19 Mar 2016
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

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!