Q:

Write a function rid_multiple_blanks that will receive a string as an input argument. The string contains a sentence that has multiple blank spaces in between some of the words

0

 Write a function rid_multiple_blanks that will receive a string as an 

input argument. The string contains a sentence that has multiple 

blank spaces in between some of the words. The function will return 

the string with only one blank in between words. For example,

>> mystr = 'Hello and how are you?';

>> rid_multiple_blanks(mystr)

ans =

Hello and how are you?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

rid_multiple_blanks.m

function newstr = rid_multiple_blanks(str)

% Deletes multiple blanks from a string

% Format of call: rid_multiple_blanks(input string)

% Returns a string with multiple blanks replaced

% by a single blank space

while length(strfind(str,' ')) > 0

 str = strrep(str,' ', ' ');

end

newstr = str;

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now