不知道从哪里开始MATLAB

时间:2017-09-30 19:54:42

标签: matlab

我必须让用户输入'str'(这是一个字符串)和'letter'(一个字母)。该函数必须创建'newstr'(一个新的字符串),删除所有'letter'实例。还有另一个名为'num'(数字)的输出,显示实际从'str'中删除的字母数。

我无法弄清楚从哪里开始。我想使用while循环然后使用if语句并询问'letter'是否在'str'中是第一步,但我不知道语法是什么。

我已经尝试过的代码:

function [newstr, num] = removeLetter(str, letter)
% This program will take the 'str' that the user inputs and will 
% remove all instances of 'letter' from it. It will ignore the case  
% of the letters.
% After it removes all instances of 'letter', it will output the new 
% string
% that is produced (newstr). It will also output the number of that  
% letter taken out of the str.

%Inputs:
% str - string that user inputs
% letter - the letter that should be taken out of the string

% Outputs:
% newstr - the string that is left over after the letters are taken 
%  out
% num - the number of letters taken out of the string

s = 0; %Used for the number of instances of 'letter' that is removed   
% from 'str'

while str == letter
    if 

0 个答案:

没有答案