I can't figure out what is wrong with the code. MATLAB

1 回表示 (過去 30 日間)
Kratos
Kratos 2015 年 2 月 3 日
回答済み: Star Strider 2015 年 2 月 3 日
function y = camelCase(x)
%camelCase Convert name with spaces to camelCase.
y(1) = lower(x(1));
% find the spaces
indall = find(x==' ');
% figure out where consecutive are
% and remove all
consec = diff(indall)==1;
ind = indall;
ind(consec) = [];
y = x;
y(min(ind+1,end)) = upper(y(min(ind+1,end)));
y(indall) = '';
end
This is what I am supposed to get
% out1 = camelCase('This Is a Variable')
% out1 => 'thisIsAVariable'
%
% out2 = camelCase('HERE IS AN EXAMPLE')
% out2 => 'hereIsAnExample'
%
% out3 = camelCase('the CoW jUmPeD over THE mooN')
% out3 => 'theCowJumpedOverTheMoon'
BUT I keep getting something else. ANY HELP!!!!!

採用された回答

Star Strider
Star Strider 2015 年 2 月 3 日
There may be several ways to accomplish what you want.
Here is one:
S = 'HERE IS AN EXAMPLE';
sp = strfind(S, ' ');
uc = upper(S(sp+1));
SL = lower(S);
SL(sp+1) = uc;
Out = strrep(SL, ' ','')
produces:
Out =
hereIsAnExample

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by