problem in compare strings

조회 수: 1 (최근 30일)
huda nawaf
huda nawaf 2012년 7월 31일
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

채택된 답변

per isakson
per isakson 2012년 7월 31일
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개)

Jan
Jan 2012년 7월 31일
str1 = 'Animation*;
str2 = 'Animation';
strncmp(str1, str2, length(str2))

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by