Clear Filters
Clear Filters

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

4 views (last 30 days)
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.

Accepted Answer

ME
ME on 26 Oct 2019
Edited: ME on 26 Oct 2019
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

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!