Cody

# Problem 2625. Shorten pathname

Solution 1947451

Submitted on 24 Sep 2019
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 = 'C:\foo\bar\baz\qux'; assert(isequal(shorten(x),'C:\..\qux'))

t1 = 3 7 11 15

Unable to perform assignment because the left and right sides have a different number of elements. Error in shorten (line 5) x(l1:l2)='..' Error in Test1 (line 2) assert(isequal(shorten(x),'C:\..\qux'))

2   Fail
x = 'this\is\just\a\test'; assert(isequal(shorten(x),'this\..\test'))

t1 = 5 8 13 15

Unable to perform assignment because the left and right sides have a different number of elements. Error in shorten (line 5) x(l1:l2)='..' Error in Test2 (line 2) assert(isequal(shorten(x),'this\..\test'))

3   Fail
x = 'testing\testing\123.mat'; assert(isequal(shorten(x),'testing\..\123.mat'))

t1 = 8 16

Unable to perform assignment because the left and right sides have a different number of elements. Error in shorten (line 5) x(l1:l2)='..' Error in Test3 (line 2) assert(isequal(shorten(x),'testing\..\123.mat'))

4   Fail
x = 'testing\t1\t2\t3\t4\t5\t6\t7\t8\t9\t10\123.mat'; assert(isequal(shorten(x),'testing\..\123.mat'))

t1 = 8 11 14 17 20 23 26 29 32 35 39

Unable to perform assignment because the left and right sides have a different number of elements. Error in shorten (line 5) x(l1:l2)='..' Error in Test4 (line 2) assert(isequal(shorten(x),'testing\..\123.mat'))

5   Fail
x = 'corp.company_name.com\dir1\dir2\dir3\dir4\file'; assert(isequal(shorten(x),'corp.company_name.com\..\file'))

t1 = 22 27 32 37 42

Unable to perform assignment because the left and right sides have a different number of elements. Error in shorten (line 5) x(l1:l2)='..' Error in Test5 (line 2) assert(isequal(shorten(x),'corp.company_name.com\..\file'))

6   Fail
x = 'dir1\dir2\dir3\d.txt'; assert(isequal(shorten(x),'dir1\..\d.txt'))

t1 = 5 10 15

Unable to perform assignment because the left and right sides have a different number of elements. Error in shorten (line 5) x(l1:l2)='..' Error in Test6 (line 2) assert(isequal(shorten(x),'dir1\..\d.txt'))

7   Fail
x = 'dir1\dir#2\dir_3\dir%4\dir(5)\dir+6\d.txt'; assert(isequal(shorten(x),'dir1\..\d.txt'))

t1 = 5 11 17 23 30 36

Unable to perform assignment because the left and right sides have a different number of elements. Error in shorten (line 5) x(l1:l2)='..' Error in Test7 (line 2) assert(isequal(shorten(x),'dir1\..\d.txt'))

### Community Treasure Hunt

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

Start Hunting!