怎么样得到一个字符串的后面几个字符?

解决方案 »

  1.   

    java.lang.Stringpublic String substring(int beginIndex)Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string. 
    Examples:  "unhappy".substring(2) returns "happy"
     "Harbison".substring(3) returns "bison"
     "emptiness".substring(9) returns "" (an empty string)
     
    Parameters:
    beginIndex - the beginning index, inclusive. 
    Returns:
    the specified substring. 
    Throws: 
    IndexOutOfBoundsException - if beginIndex is negative or larger than the length of this String object.
      

  2.   

    String src = "abchehehehe";
    String s = "abc";// 得到src中“abc”之后的所有字符串
    String result = src.substring(src.indexOf(s)+s.length);// hehehehe// 得到src中“abc”之后的长度为4的字符串String result = src.substring(src.indexOf(s)+s.length , src.indexOf(s)+s.length + 4); //hehe
      

  3.   

    String src = "abchehehehe";
    String s = "abc";
    int index = src.indexOf(s)+s.length; // "abc"后的位置// 得到src中“abc”之后的所有字符串
    String result = src.substring(index);// hehehehe// 得到src中“abc”之后的长度为4的字符串
    String result1 = src.substring(index,index+4); //hehe
      

  4.   

    String str = "adfasdf";
         int n = 3;
         System.out.println(str.substring(str.length() - n));
      

  5.   

    subString(int startPosition, int endPosition)
      

  6.   

    public String last(String str,String count)
    {
        if(str == null)
            return null;
        if(count <= 0)
            return null;
        if(str.length()<=count)
            return str;
        return str.substring(str.length()-count);
    }
      

  7.   

    用substring()
    假如需要连接使用
    那么在使用的过程中需要注意,因为String类型比较特殊。
      

  8.   

    aico(aico) 的方法就可以了,不过count应该是int
    public String last(String str,int count){
        if(str == null)
            return null;
        if(count <= 0)   
            return null;
        if(str.length()<=count)
            return str;
        return str.substring(str.length()-count);
    }
      

  9.   

    1
    substring
    public String substring(int beginIndex)
    Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string. 
    Examples:  "unhappy".substring(2) returns "happy"
     "Harbison".substring(3) returns "bison"
     "emptiness".substring(9) returns "" (an empty string)
     Parameters:
    beginIndex - the beginning index, inclusive. 
    Returns:
    the specified substring. 
    Throws: 
    IndexOutOfBoundsException - if beginIndex is negative or larger than the length of this String object.2
    substring
    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. 
    Returns:
    the specified substring. 
    Throws: 
    IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
      

  10.   

    精髓在这3句:
    String str = "adfasdf";
         int n = 3;
         System.out.println(str.substring(str.length() - n));
      

  11.   

    sS
    str.substring(str.length() - n,str.length());
      

  12.   

    错了,是substring(str.length()-n,n)
    字符串从指定字符位置开始,且具有指定长度。
      

  13.   

    substring(str.length()-n,n)
    与substring(str.length()-n)是等同的.
      

  14.   

    str.substring(str.length() - n, str.length())
    与substring(str.length()-n)是等同的.