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

Popular posts from this blog

java - Unable to make sub reports with Jasper -

sql - The object name contains more than the maximum number of prefixes. The maximum is 2 -

scala - play framework: Modules were resolved with conflicting cross-version suffixes -