Borrar filtros
Borrar filtros

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

4 visualizaciones (últimos 30 días)
Kratos
Kratos el 3 de Feb. de 2015
Respondida: Star Strider el 3 de Feb. de 2015
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!!!!!

Respuesta aceptada

Star Strider
Star Strider el 3 de Feb. de 2015
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

Más respuestas (0)

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by