String color = "";
String size  = "";
String values = "Lady Size:M.Select Color:As the Picture";
size = "Lady Size:M.Select";
color = "Color:As the Picture";
如何截取

解决方案 »

  1.   

    public class TestIndex {
    String color = "";
    String size = "";
    public static String values = "Lady Size:M.Select Color:As the Picture";
    public static void main(String[] args){
    splitString();
    }
    public static  void splitString(){
    int index=values.indexOf("Color");
    System.out.println(values.subSequence(0, index));
    System.out.println(values.subSequence(index,values.length() ));
    }
    }    
      

  2.   


    size = values.substring(0,values.indexOf("Select")+6);
    color = values.substring(values.indexOf("Color:"));
      

  3.   

    一般字符串的截取都是用到用indexOf和substring两个方法。。看看API。。String类中的方法。 。应该就可以搞定
      

  4.   

    [code=Java]
    public static void main(String args[]) {
    String color = "";
    String size = "";
    String values = "Lady Size:M.Select Color:As the Picture"; int position = getPosition(values," ",2); color = values.substring(0, position);
    size = values.substring(position); System.out.println(position);
    System.out.println("color = " + color );
    System.out.println("size = " + size); } public static int getPosition(String aimStr, String substr, int sequent) { if (sequent < 0)
    return 0;
    String[] tmpArray = aimStr.split(substr);
    if (sequent > tmpArray.length)
    return -1;
    String tmp = tmpArray[sequent] + substr;
    return aimStr.indexOf(tmp); }
    [/code
    写个小函数
      

  5.   

    String color = "";
    String size = "";
    String values = "Lady Size:M.Select Color:As the Picture";
    size = "Lady Size:M.Select";
    color = "Color:As the Picture";
    String[] strs = values.split("\\s+(?=Color)");
    size = strs[0];
    color = strs[1];
      

  6.   

    我用的这个方法,因为M 是尺寸大小,也有可能是xxl,或者其他的,所以用这个比较好,正则表达式