Remove a string from another string

46 ビュー (過去 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 Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by