c# - Cannot add 1 to LastIndexOf() method -
i have method gets substring based on last occurrence of forward slash character.
path.substring(path.lastindexof('/'), path.length - path.lastindexof('/') )
given string the/quick/brown/fox
, substring result of /fox
. rid of forward slash character such fox
result.
i try add 1 lastindexof()
method i'm getting argumentoutofrangeexception
.
path.substring(path.lastindexof('/') + 1, path.length - path.lastindexof('/'))
the lastindexof()
method returns int
, why adding 1 cause error?
have considered simpler string.split
?
var str = "the/quick/brown/fox"; var result = str.split('/').last(); //result = "fox"
Comments
Post a Comment