Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
253 views
Welcome To Ask or Share your Answers For Others

1 Answer

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';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...