What happens when you try it?Ana Yo wrote:What would "hello".substring(5) return?
you have to provide start index and end index to which you want to get substringAna Yo wrote:What would "hello".substring(5) return?
The substring() method extracts the characters from a string, between two specified indices, and returns the new sub string.
This method extracts the characters in a string between "start" and "end", not including "end" itself.
ASP.NET Software development companies
Dave Tolls wrote:If that was in response to me, then my question still stands.
Why does "hello".substring(5) return an empty string, and "hello".substring(6) an IndexOutOfBounds?
To me it's counter-intuitive. 5 is as much "out of bounds" as 6...
It returns a String. 0 is not a String. Do you mean a length of 0? An Empty String will have a length of 0Ana Yo wrote:It ouputted 0
Please check the String documentation for details of overloaded methods before posting that sort of thing.sohail hussain wrote:. . . you have to provide start index and end index to which you want to get substring
Afraid that isn't correct, as you will see from the appropriate documentation link.Example...
"hello".substring(2, 4)
It will print "llo" . . .
I personally checked it compiled well but only difference is output is "ll" not "llo"Campbell Ritchie wrote:
Please check the String documentation for details of overloaded methods before posting that sort of thing.sohail hussain wrote:. . . you have to provide start index and end index to which you want to get substring
Afraid that isn't correct, as you will see from the appropriate documentation link.Example...
"hello".substring(2, 4)
It will print "llo" . . .
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|