Cody

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

Solution 2266014

Submitted on 9 May 2020
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   Fail
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))

ans = 1×31 uint16 row vector Columns 1 through 30 73 32 119 97 110 116 32 116 111 32 115 112 108 105 116 32 116 104 105 115 58 32 102 114 111 109 32 116 104 105 Column 31 115

Output argument "y1" (and maybe others) not assigned during call to "SplitString". Error in Test1 (line 2) [y1,y2] = SplitString(x,':');

2   Fail
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))

ans = 1×34 uint16 row vector Columns 1 through 30 84 104 105 115 32 111 110 101 32 100 111 101 115 32 110 111 116 32 104 97 118 101 32 116 104 101 32 100 105 118 Columns 31 through 34 105 100 101 114

Output argument "y1" (and maybe others) not assigned during call to "SplitString". Error in Test2 (line 2) [y1,y2] = SplitString(x,':')

3   Fail
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))

ans = 1×39 uint16 row vector Columns 1 through 30 84 104 105 115 32 115 101 110 116 101 110 99 101 32 115 104 111 117 108 100 44 32 110 111 116 32 104 97 118 101 Columns 31 through 39 32 97 32 99 111 109 109 97 46

Output argument "y1" (and maybe others) not assigned during call to "SplitString". Error in Test3 (line 2) [y1,y2] = SplitString(x,',')

4   Fail
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))

ans = 1×43 uint16 row vector Columns 1 through 30 68 105 118 105 100 101 32 111 110 108 121 32 64 32 97 116 32 116 104 101 32 64 32 102 105 114 115 116 32 105 Columns 31 through 43 110 115 116 97 110 99 101 32 111 102 32 64 46

Output argument "y1" (and maybe others) not assigned during call to "SplitString". Error in Test4 (line 2) [y1,y2] = SplitString(x,'@')

5   Fail
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))

ans = 1×40 uint16 row vector Columns 1 through 30 84 97 107 101 32 116 104 97 116 44 32 97 110 100 32 116 104 105 115 44 32 97 110 100 32 115 111 109 101 116 Columns 31 through 40 104 105 110 103 32 101 108 115 101 46

Output argument "y1" (and maybe others) not assigned during call to "SplitString". Error in Test5 (line 2) [y1,y2] = SplitString(x,',')