Cody

# Problem 44. Trimming Spaces

Solution 734699

Submitted on 14 Sep 2015 by toofan
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% a = 'no extra spaces'; b = 'no extra spaces'; assert(isequal(b,removeSpaces(a)))

ig = 2 1 2 2 1 3 1 4 2 5 1 6 1 7 1 8 1 9 1 10 2 11 1 12 1 13 1 14 1 15 1 16 1 17 2 18 2 19 startIndex = 3 endIndex = 17 b = no extra spaces

2   Pass
%% a = ' lots of space in front'; b = 'lots of space in front'; assert(isequal(b,removeSpaces(a)))

ig = 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 1 9 1 10 1 11 1 12 2 13 1 14 1 15 2 16 1 17 1 18 1 19 1 20 1 21 2 22 1 23 1 24 2 25 1 26 1 27 1 28 1 29 1 30 2 31 2 32 startIndex = 9 endIndex = 30 b = lots of space in front

3   Pass
%% a = 'lots of space in back '; b = 'lots of space in back'; assert(isequal(b,removeSpaces(a)))

ig = 2 1 2 2 1 3 1 4 1 5 1 6 2 7 1 8 1 9 2 10 1 11 1 12 1 13 1 14 1 15 2 16 1 17 1 18 2 19 1 20 1 21 1 22 1 23 2 24 2 25 2 26 2 27 2 28 2 29 2 30 2 31 startIndex = 3 endIndex = 23 b = lots of space in back

4   Pass
%% a = ' space on both sides '; b = 'space on both sides'; assert(isequal(b,removeSpaces(a)))

ig = 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 1 9 1 10 1 11 1 12 1 13 2 14 1 15 1 16 2 17 1 18 1 19 1 20 1 21 2 22 1 23 1 24 1 25 1 26 1 27 2 28 2 29 2 30 2 31 2 32 2 33 startIndex = 9 endIndex = 27 b = space on both sides

5   Pass
%% a = sprintf('\ttab in front, space at end '); b = sprintf('\ttab in front, space at end'); assert(isequal(b,removeSpaces(a)))

ig = 2 1 2 2 1 3 1 4 1 5 1 6 2 7 1 8 1 9 2 10 1 11 1 12 1 13 1 14 1 15 1 16 2 17 1 18 1 19 1 20 1 21 1 22 2 23 1 24 1 25 2 26 1 27 1 28 1 29 2 30 2 31 2 32 2 33 2 34 2 35 startIndex = 3 endIndex = 29 b = tab in front, space at end

### Community Treasure Hunt

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

Start Hunting!