finding a string in a character array

13 visualizzazioni (ultimi 30 giorni)
Ngozika Onunkwo
Ngozika Onunkwo il 19 Mar 2016
Modificato: Ngozika Onunkwo il 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

Risposte (1)

Jan
Jan il 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

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by