matlab - Compare last charaters of strings -
i need compare last characters of strings in matlab. natively following:
string = 'foobar'; len_string = length(string); if len_str_2 >= 3 str_suffix = str_2(len_str_2 - 2:len_str_2); strcmp('bar', str_suffix) end
is there simpler way this? strncmp
can compare first n
characters.
this sounds typical job regular expression:
any(regexp('foobar','bar$')) %% return true any(regexp('foobars','bar$')) %% return false
the dollar sign enforces pattern @ end of string.
Comments
Post a Comment