classifyStrings

classifyStrings - relationship = 'Not so much'; %will...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function relationship = classifyStrings(str1,str2) %function to determine if the two strings possess any of the following %qualties, returning only the most inclusive, and output a string as %specified if any of the cases are true: % CASE: | OUTPUT: % - The two strings are exactly the same | 'Bingo!' % | % - The two strings are the same, ignoring caps | 'Really quite similar' % | % - The smaller string appears in the larger | 'Not so much' % string, disregarding case | % | % - None of the above are true, or one of the | 'Epic fail' % inputs is not a string %usage: relationship = classifyStrings(str1,str2) if strcmp(str1,str2) relationship = 'Bingo!'; %will display 'Bingo!' if str1==str2, the boolean. .. %expression must be true elseif strcmpi(str1,str2) relationship = 'Really quite similar'; %will display 'Really quite similar'. .. %if str1==str2 (the function strcmpi will ignore the cases),. .. %the expression must be true elseif ~isempty(strfind(lower(str1),lower(str2)))
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: relationship = 'Not so much'; %will display 'Not so much' if str2 is an element. .. %of str1; the isempty function checks to see if the answer is an %empty bracket (which is why the ~ is used, because we want the %non-empty bracket and returns a logical) and the strfind function %locates the position if the second string is in the first elseif ~isempty(strfind(lower(str2),lower(str1))) relationship = 'Not so much'; %will display 'Not so much' if str1 is an element. .. %of str2; the isempty function checks to see if the answer is an %empty bracket (which is why the ~ is used, because we want the %non-empty bracket and returns a logical) and the strfind function %locates the position if the second string is in the first else relationship = 'Epic fail'; %if any of the if, elseif statements are false,. .. %then 'Epic fail' will be displayed end end...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Tech.

Ask a homework question - tutors are online