Cody

# Problem 2073. Split a given string from the first instance of a given character

Solution 1437046

Submitted on 8 Feb 2018 by J. S. Kowontan
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
x='I want to split this: from this'; [y1,y2] = SplitString(x,':'); y1_correct = 'I want to split this'; y2_correct = ': from this'; assert(isequal(y1,y1_correct)) assert(isequal(y2,y2_correct))

varargout = 2×1 cell array {'I want to split this'} {' from this' } varargout = 2×1 cell array {'I want to split this'} {': from this' }

2   Pass
x='This one does not have the divider'; [y1,y2] = SplitString(x,':') y1_correct = 'This one does not have the divider' y2_correct = '' assert(isequal(y1,y1_correct)) assert(isequal(y2,y2_correct))

varargout = 1×1 cell array {'This one does not have the divider'} varargout = 1×2 cell array {'This one does not have the divider'} {':'} varargout = 1×2 cell array {'This one does not have the divider'} {0×0 char} y1 = 'This one does not have the divider' y2 = 0×0 empty char array y1_correct = 'This one does not have the divider' y2_correct = 0×0 empty char array

3   Pass
x='This sentence should, not have a comma.'; [y1,y2] = SplitString(x,',') y1_correct = 'This sentence should' y2_correct = ', not have a comma.' assert(isequal(y1,y1_correct)) assert(isequal(y2,y2_correct))

varargout = 2×1 cell array {'This sentence should'} {' not have a comma.' } varargout = 2×1 cell array {'This sentence should'} {', not have a comma.' } y1 = 'This sentence should' y2 = ', not have a comma.' y1_correct = 'This sentence should' y2_correct = ', not have a comma.'

4   Pass
x='Divide only @ at the @ first instance of @.'; [y1,y2] = SplitString(x,'@') y1_correct = 'Divide only ' y2_correct = '@ at the @ first instance of @.' assert(isequal(y1,y1_correct)) assert(isequal(y2,y2_correct))

varargout = 4×1 cell array {'Divide only ' } {' at the ' } {' first instance of '} {'.' } varargout = 4×1 cell array {'Divide only ' } {'@ at the @ first instance of @.'} {' first instance of ' } {'.' } y1 = 'Divide only ' y2 = '@ at the @ first instance of @.' y1_correct = 'Divide only ' y2_correct = '@ at the @ first instance of @.'

5   Pass
x='Take that, and this, and something else.'; [y1,y2] = SplitString(x,',') y1_correct = 'Take that' y2_correct = ', and this, and something else.' assert(isequal(y1,y1_correct)) assert(isequal(y2,y2_correct))

varargout = 3×1 cell array {'Take that' } {' and this' } {' and something else.'} varargout = 3×1 cell array {'Take that' } {', and this, and something else.'} {' and something else.' } y1 = 'Take that' y2 = ', and this, and something else.' y1_correct = 'Take that' y2_correct = ', and this, and something else.'