How to return sub string from String
Hi all im trying to return a sub String from a String. I have a small String saved as "myText" that contains lots of characters but just two numbers. The numbers are inbetween two markers, "start" & "finish". so the String would read: hello,goodbye(start) 35 (finish) hello,goodbye.
i need to return just the numbers (the characters inbetween the markers)
the way I have tried to do this is as follows:
return myText.substring(myText.lastIndexOf(start), myText.indexOf(finish));
however when I run the code it returns goodbye 35.
Can anyone see what im doing wrong?
Re: How to return sub string from String
I don't see why you are getting that particular returned string, but that aside the methods indexOf return the start location of the found string, so you should add on the length of the string to get the index position of the end of the string