problem in compare strings

1 vue (au cours des 30 derniers jours)
huda nawaf
huda nawaf le 31 Juil 2012
hi,
if I want compare two strings
ex.
str1='Animation|Children's|Comedy'
i want to check just the first word and whatever the others words
str1='Animation*' str2= 'Animation'
i.e can I compare strcmp(str1,str2)?
thanks

Réponse acceptée

per isakson
per isakson le 31 Juil 2012
Try this
str1 = 'Animation|Children''s|Comedy';
str2 = 'Animation*';
str3 = 'Animation';
ism = strcmp( str3, regexp( str1, '\|', 'split' ) );
>> whos ism
Name Size Bytes Class Attributes
ism 1x3 3 logical
>> ism
ism =
1 0 0
Note
  1. double blip in "Children''s"
  2. strcmp make exact comparisons of strings - no wildcards as in 'Animation*';
  3. strfind is an alternative to strcmp - see the documentation
  1 commentaire
huda nawaf
huda nawaf le 31 Juil 2012
thanks

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 31 Juil 2012
str1 = 'Animation*;
str2 = 'Animation';
strncmp(str1, str2, length(str2))
  1 commentaire
huda nawaf
huda nawaf le 31 Juil 2012
thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by