public static void main(String[] args) {
        
                String st, ss = "什么是数据库";
st = ss.substring(2, 2);
System.out.print(st);
}
可是输出结果什么都没有,也没有报错!晕!

解决方案 »

  1.   


    String st,ss = "什么是数据库"; 
            st = ss.substring(2,3); 
            System.out.print(st); 
      

  2.   

    没有是正常的咩
    substring(截取开始位置,截取结束位置);
    从2开始,在2结束,当然什么的没截取到.
    API的疑问,lz要多多查阅文档.
      

  3.   

    public String substring(int beginIndex,
                            int endIndex)
    Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. 
    Examples:  "hamburger".substring(4, 8) returns "urge"
     "smiles".substring(1, 5) returns "mile"

     Parameters:
    beginIndex - the beginning index, inclusive.
    endIndex - the ending index, exclusive. 
      

  4.   


    st = ss.substring(2, 2); //是index2开始index2!
    改为
    st = ss.substring(2, 4);//这就是你想要的结果! 
      

  5.   


     你是不是理解错误了substring()方法阿?
     
      第一个参数是从哪里起 第二个是结束  你这里从2起截到2 肯定没东西阿!
      你是被JAVASCRIPT里面的substr()搞混淆了吧!
      

  6.   

    大家说的都对!
    substring——截取开始位置......截取结束位置(不包括);
      

  7.   

    晕菜,有了才见鬼了呢。建议楼主好好看下api
      

  8.   

    substring(2, 3)第一个参书市开始位置,第二个失结束字符,但不包括结束字符
      

  9.   

    LZ这样的问题可以直接稍加思考再查api啊!遇到问题就问可不是好习惯哦!
      

  10.   

    substring(开始位置,结束位置); 
      

  11.   

    要是我想把所有的都提取出来呢?
    例如:
    public static void main(String[] args) { 
             
                    String st, ss = "什么是数据库"; 
    st = ss.substring(1, 7); } 
    要把“什么是数据库”,的全部提取出来,该怎么写!
      

  12.   

    要把“什么是数据库”,的全部提取出来,该怎么写!————————————————————————————st = ss.substring(0);
      

  13.   

    st = ss.substring(2, 2); 
    起始位置2,结束位置2,2-2=0,能打出东西就怪了。
      

  14.   

    substring的方法的使用你要搞明白,
    这个要注意和sql中的区分,我估计你是记成sql中的了。
      

  15.   


    public String substring(int beginIndex,
                            int endIndex)返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex 处开始,一直到索引 endIndex - 1 处的字符。因此,该子字符串的长度为 endIndex-beginIndex。 
    示例:  "hamburger".substring(4, 8) returns "urge"
     "smiles".substring(1, 5) returns "mile"