Remove a string from another string

18 visualizzazioni (ultimi 30 giorni)
Tejas
Tejas il 6 Mag 2021
Risposto: Ezma Nasr il 15 Feb 2023
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.

Risposta accettata

KSSV
KSSV il 6 Mag 2021
str1 = 'bio-inspired' ;
str2 = 'bioinspired' ;
str=setdiff(str1,str2)
str = '-'
  4 Commenti
KSSV
KSSV il 6 Mag 2021
Huumh....because s is present once in the string. Need to check other ways.
Tejas
Tejas il 6 Mag 2021
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.

Accedi per commentare.

Più risposte (1)

Ezma Nasr
Ezma Nasr il 15 Feb 2023
str='bio-inspired';
newStr = erase(str,"-")

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by