废话不说,直接看代码:
filePath = "1111abcdefghijklmnabcdefghij";
authorImage.setText(filePath);
int index = filePath.lastIndexOf("a");
int index_t = filePath.lastIndexOf("c",index);
authorImageName.setText(filePath.substring(index+1, index+index_t));
结果:index=18 (正确) index_t=6 (无法理解)
按我的想法index_t=2 不知道坛子里面的高手怎么解释这个问题
filePath = "1111abcdefghijklmnabcdefghij";
authorImage.setText(filePath);
int index = filePath.lastIndexOf("a");
int index_t = filePath.lastIndexOf("c",index);
authorImageName.setText(filePath.substring(index+1, index+index_t));
结果:index=18 (正确) index_t=6 (无法理解)
按我的想法index_t=2 不知道坛子里面的高手怎么解释这个问题
首先申明一点 这个index的值都是相对于整个字符串从前往后取得值 你的第二个值为6 就是从最后一个a往字符串前找 找到第一个c 再返回这个c的index 那么这个c就是1111abc这个c 那么他在整个字符串中的index是6 没问题啊...
汗。。我以为是在index-string.length的字符串里面查找的。
如果按你说的话,恩,可以解释通,我再看看他的源代码去