%% SL7
str = 'Hello, world!';
length(str)
double(str)
str(3:8)
%% SL12
sprintf('Value of pi is: %0.5f, value of 5*pi is: %0.5f', pi, 5*pi)

sprintf('This is 50%%\n\n\n')

tx = 'test_A';
sprintf('This is a measurement set: %s', tx)

%% SL23
s = 'this is a big book'
s(s ~= ' ')
s(s > ' ')
s(s > 32)

%% SL24
clear; clc;
sen    = 'This-sentence-is-for-testing-purposes-only.';
remain = sen;
word   = 1;
while ~isempty(remain)
    [token, remain] = strtok(remain, '-');
    fprintf('%2.0f. word is: %s\n', word, token);
    word = word + 1;
end
fprintf('The string ''is'' is used %2.0fx.\n', length(strfind(sen, 'is')));

%% SL34
clear, clc
st = 'how are you?';
length(strfind(st, ' '))
% OR
sum(st == ' ')

st = 'MATLAB is CaSe sEnSiTiVe!!!';
st = lower(st)
length(st)

%% SL35
clear, clc
[V, S, d] = main('cuboid', 2, 5, 3)
% functions follows at the end of file

%% SL38
str = input('Enter a text: ', 's');
sep = input('Enter separator: ', 's');
 
if isempty(sep)    % treats all cases when sep = '' / ' '
    sep = ' ';
    fprintf('space ('' '') is used instead of nothing');
end

words   = cell(1, 1); % allocation
nVowels = zeros(1, 1); % allocation
here    = 1;
while ~isempty(str)
    [token, str]   = strtok(str, sep);
    words{here}    = token;
    nVowels(here)  = length(regexp(token, '[aeiyou]'));
    here           = here + 1;
end
celldisp(words);
fprintf('%s\n', mat2str(nVowels));


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [V, S, d] = main(gType, a, b, c)
%% documentation should be here!!

V = NaN; S = NaN; d = NaN;
switch gType
    case 'cuboid'
        if nargin == 4
            [V, S, d] = cuboid(a, b, c);
        else
            fprintf('Wrong input!');
        end
    case 'cylinder'
        if nargin == 3
            [V, S, d] = cylinder1(a, b);
        else
            fprintf('Wrong input!');
        end
    otherwise, disp('Bad input.');
end

    function [V, S, d] = cuboid(a, b, c)
        V = a*b*c;
        S = 2*(a*b+a*c+b*c);
        d = sqrt(a^2+b^2+c^2);
    end

    function [V, S, d] = cylinder1(r, h)
        V = pi*r^2*h;
        S = 2*pi*r*(r+h);
        d = sqrt(h^2 + 4*r^2);
    end
end






