Remove a string from another string

45 次查看(过去 30 天)
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 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by