%% SL07
str = 'this is arbitrary string';
stringInDouble = double(str);
this = str(1:4);

%% 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 ~= ' ')

% using ASCII
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
st = 'how are you?';
length(strfind(st, ' '))

sum(st == ' ')

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

%% SL35
% see attached file
[V, S, d] = volumeCalculator('cuboid', 1, 1, 1)
[V, S, d] = volumeCalculator('cylinder', 1, 1)

%% SL37
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));

% improved using strsplit
clear; clc;
str = input('Enter a text: ', 's');
sep = input('Enter separator: ', 's');
if isempty(str)
    fprintf('''string'' is empty\n');
    return;
end
if isempty(sep)
    sep = ' ';
    fprintf('space ('' '') is used instead of nothing\n');
end
 
words  = strsplit(str, sep);
VS     = regexp(words, '[aeiyou]');
nVowels = cellfun(@length, VS);

celldisp(words);
fprintf('%s\n', mat2str(nVowels));
