remove occurrences of given characters in a string using find and []

1 次查看(过去 30 天)
function f=test(s,c)
f=regexp(find(s=='c'))=[];
end
my s='now is the time for all good'
I am trying to remove all the o's in the sentence. However, when I go to test it I get an error with the second eqal sign --> =[];
it says incorrect use of '=' operator. However, when I try to change it, i still get the same error.

采纳的回答

ME
ME 2019-10-26
编辑:ME 2019-10-26
If you absolutely have to use find then you could use
function f=test(s,c)
idx=find(s==c);
s(idx)=[];
f=s;
end
Or, you could simplify it by using regular expressions instead:
function f=test(s,c)
f= regexprep(s,c,'')
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by