MATLAB: Finding the word in a string in an editbox

if and else statementsisemptymetacharacters

I want to input a string in the edit box,if I click on a pushbutton, the callback function of the pushbutton checks whether the string has the letter 'a'.if it does display'good'on the static text if it doesn't display'not good'.

Best Answer

Ngozika - if you are using GUIDE to create your GUI, then you could try the following (which assumes that your pushbutton, edit text, and static text controls are named (tagged) as pushbutton1, edit1, and text1 respectively)
function pushbutton1_Callback(hObject, eventdata, handles)
strToCheck = char(get(handles.edit1,'String'));
if ~isempty(strfind(strToCheck,'a'))
set(handles.text1,'String','good');
else
set(handles.text1,'String','not good');
end
In the above, we use strfind to determine if the character 'a' is within the string that the user typed in.