String.substring(5).replace(“”,“”)//空字符串的奇怪行为

时间:2013-05-09 11:15:14

标签: java android string replace substring

注意:我在Android项目中遇到此问题,在Eclipse中。

这是我的代码:

    String str = "just_a_string";
    System.out.println("]" + str + "[");
    System.out.println("]" + str.replace("", "") + "[");
    System.out.println("]" + str.substring(5) + "[");
    System.out.println("]" + str.substring(5).replace("", "") + "[");
    System.out.println("]" + str.substring(3, 8) + "[");
    System.out.println("]" + str.substring(3, 8).replace("", "") + "[");
    System.out.println("]" + "sdajndan".substring(5).replace("", "") + "[");

这是输出

05-09 19:09:20.570: I/System.out(23801): ]just_a_string[
05-09 19:09:20.570: I/System.out(23801): ]just_a_string[
05-09 19:09:20.570: I/System.out(23801): ]a_string[
05-09 19:09:20.570: I/System.out(23801): ]a_s[      **
05-09 19:09:20.570: I/System.out(23801): ]t_a_s[
05-09 19:09:20.570: I/System.out(23801): ]t_[       **
05-09 19:09:20.570: I/System.out(23801): ][         **

显然,标有**的行是意料之外的。

有人可以解释一下吗?非常感谢任何输入!!

0 个答案:

没有答案
相关问题