필터 지우기
필터 지우기

strrep for more replacing using if

조회 수: 1 (최근 30일)
Adam Aust
Adam Aust 2014년 2월 18일
댓글: Jos (10584) 2014년 2월 19일
s= strrep(origStr, oldSubstr, newSubstr)
str1==strrep(str,'sport','1');
str2==strrep(str1,'art','2');
str3==strrep(str2,'art_u','3'); should be 3 but when print it became 2_u it's error
what is the error ? and how to use if condition with strrep to specify any word for replacing?? if u have more replacing ? art=2 , and when 'art_u' it's one word it will be 2_u it is error the output art=2 so to be art_u= 2_u is wrong should be 3 only how to solve ???

채택된 답변

Jos (10584)
Jos (10584) 2014년 2월 18일
편집: Jos (10584) 2014년 2월 18일
Remove the semi-colons and see what happens ...
str = 'hello sport art art_u' ; % example string
str1 = strrep(str,'sport','1')
str2 = strrep(str1,'art','2') % not what you want
str3 = strrep(str2,'art_u','3')
You can switch the last two statements:
str2 = strrep(str1,'art_u','3')
str3 = strrep(str2,'art','2')
NB You most likely want to assign (A = B) and not compare (A == B)
  댓글 수: 1
Jos (10584)
Jos (10584) 2014년 2월 19일
Can you rephrase your questions in proper English? As a non-native speaker I do not understand what you mean by " plz can u clear ? and check it ? ". Google Translate does not help either ...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by