%% Call Method Specified at Runtime
% Search for a text pattern in a string using variables for the pattern and for the search method. These variables could be set at runtime from user input.
% Choose method, startsWith, and identify pattern, str.

fnc = 'startsWith';
str = java.lang.String('Four score');

%
% Identify text to search.

gAddress = java.lang.String('Four score and seven years ago');

%
% Search gAddress for the pattern.

javaMethod(fnc,gAddress,str)

% gAddress starts with the words Four score.
% Copyright 2012 The MathWorks, Inc.