I would like to get only the begining of string , is there an equivalent matlab that allows to say : startsWith('It-is') like in java?
Thanks
You can use the strfind
function to tell if one string starts with another. The function returns the starting index of each occurrence of the string you're looking for, or an empty array if the string is not found.
S = 'Find the starting indices of the pattern string';
strfind(S, 'It-is')
If the string started with 'It-is'
then the first index of the array returned by strfind
would be 1 (i.e. the index of the first character).
For long strings, it is faster to do this
s = (numel(a)>=numel(b)) && all(a(1:min(numel(a),numel(b)))==b(1:min(numel(a),numel(b))));
in order to have the equivalent to a.startsWith(b)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With