Removing specific characters in a string?
311 ビュー (過去 30 日間)
古いコメントを表示
Im having difficulty in deleting pre-specified characters from any given string. The characters that i am tryin to eliminate are 't' 'i' 'x' 'y'
I need a lot of help creating a function that would do this for any given string.
for example
modstr('picture') should return ans = ('pcure')
or
modstr('alex') should return ans = ('ale')
I would appreciate any help or hints regarding this since i've been working on this for literally 6 hours now.
Thank You.
2 件のコメント
Olcay
2023 年 2 月 12 日
str = 'The quick brown fox jumped over the lazy dog';
unwanted = 'tixy';
str(~ismember(str, unwanted))
採用された回答
Matt Fig
2012 年 10 月 6 日
str = 'The quick brown fox jumped over the lazy dog';
strn = regexprep(str,'[tixy]','')
0 件のコメント
その他の回答 (2 件)
Azzi Abdelmalek
2012 年 10 月 6 日
編集済み: Azzi Abdelmalek
2012 年 10 月 6 日
s='picture' % Example
s(regexp(s,'[t,i,x,y]'))=[]
3 件のコメント
Walter Roberson
2012 年 10 月 6 日
Hint #1: ismember()
Hint #2: logical indexing
2 件のコメント
Walter Roberson
2012 年 10 月 6 日
編集済み: Walter Roberson
2022 年 6 月 24 日
Consider
s == 't' | s == 'i' | s == 'x' | s == 'y'
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!