Remove a string from another string

조회 수: 53 (최근 30일)
Tejas
Tejas 2021년 5월 6일
답변: Ezma Nasr 2023년 2월 15일
I have two strings like 'bio-inspired' and 'bioinspired'. I want to essentially subtract one string from another and get '-' in the end. How can I delete all letters appearing in one string from another string? The erase function doesn't work for this case.

채택된 답변

KSSV
KSSV 2021년 5월 6일
str1 = 'bio-inspired' ;
str2 = 'bioinspired' ;
str=setdiff(str1,str2)
str = '-'
  댓글 수: 4
KSSV
KSSV 2021년 5월 6일
Huumh....because s is present once in the string. Need to check other ways.
Tejas
Tejas 2021년 5월 6일
I guess erase would work for that case. Both wouldn't work for words like 's-ams' and 'sam' to get '-s'. I'll figure something out for those cases.

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

추가 답변 (1개)

Ezma Nasr
Ezma Nasr 2023년 2월 15일
str='bio-inspired';
newStr = erase(str,"-")

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by