I can't figure out what is wrong with the code. MATLAB
1 次查看(过去 30 天)
显示 更早的评论
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!!!!!
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!