-1

I have got this one:

string = 'abcdefgh'
string(1:3) = 'abc'

Is this possible string(-6:1) = 'abcdef' .

I know this is not possible , what is the closest that is possible ; something which is similar to Python substring syntax.

Edit : I want to get rid of .jpgand C:\ from C:/hello.jpgto get just hello . Using strsplit twice is just cumbersome . I just know the length of C:\ and .jpg, but not of the whole string.

motiur
  • 1,640
  • 9
  • 33
  • 61

1 Answers1

5

Use the end statement. This will point to the last character in the vector/matrix/string/whatever. So, for instance

string(2:end-1) -> 'bcdefg';
string(end-3:end) -> 'efgh';
MrAzzaman
  • 4,734
  • 12
  • 25
  • Just a nitpick, [`end`](http://www.mathworks.com/help/matlab/ref/end.html) is not a variable, but a built-in function/statement. – chappjc Dec 04 '13 at 04:26
  • I know, I couldn't think of the right term for it. 'Function' didn't sound quite right, since that might suggest you pass the matrix to it as an argument. – MrAzzaman Dec 04 '13 at 05:50
  • I think I have to be content with this reply. – motiur Dec 04 '13 at 14:34