switch/case with wildcards?

  • Follow


I know switch/case can use multiple case_expr values, e.g., {'this','that'} and that if any of them match, that case statement will execute.  Is there a way to use wildcards in the case_expr?  Maybe something like {'th*'} would execute for the above (though that doesn't work), and would add 'through' and 'them' and 'thanythingelseyouwant' to the execution list.
0
Reply Mike 3/21/2011 7:21:05 PM

"Mike" wrote in message <im88f1$jrm$1@fred.mathworks.com>...
> I know switch/case can use multiple case_expr values, e.g., {'this','that'} and that if any of them match, that case statement will execute.  Is there a way to use wildcards in the case_expr?  Maybe something like {'th*'} would execute for the above (though that doesn't work), and would add 'through' and 'them' and 'thanythingelseyouwant' to the execution list.

% Not that I know of, however you could do something like:

method = 'thanythingelseyouwant';  % Just as an example

switch lower(method(1:2))
   case 'th'
      disp('Method is th*')
   case 't'
      disp('Method is t')
   case 'an'
      disp('Method is an')
   otherwise
      disp('Unknown method.')
end
0
Reply someone 3/21/2011 7:35:05 PM


1 Replies
426 Views

(page loaded in 0.006 seconds)

Similiar Articles:












7/23/2012 7:26:28 PM


Reply: