• Post Reply Bookmark Topic Watch Topic
  • New Topic

endsWith()  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I am trying to take the last part of the string. But, I am not quite sure how I can make it work right.

My test values were:
Sent [a,b,c,d,e,f] for Mystring and [1,2,3] for the suffix.
subthelengths = 2 = 6-4

I got back:
i=c
i=d

But, what I want to get back is d,e,f.


Specifically this line I think is where the error lies:
Code:






Code:
 
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First observation:
Why are you working with char arrays rather than with Strings?

Second observation:
I'm not quite sure why you are getting a "theString.length" of 10 because the String length is 11.

a , b , c , d , e , f
1 2 3 4 5 6 7 8 9 10 11

while the indexes are zero through 10

a , b , c , d , e , f
0 1 2 3 4 5 6 7 8 9 10

so you want a substring() of index 6 to index 10 (which is equal to string.length() - 1)

Third observation:
I'm confused why you are subtracting a suffix length of 3 ... you have commas in the string but not in the suffix? It doesn't seem like the lengths would be compatible for subtraction.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!