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 size = "";
String values = "Lady Size:M.Select Color:As the Picture";
size = "Lady Size:M.Select";
color = "Color:As the Picture";
如何截取
解决方案 »
- 简单EJB的问题~~求人解救
- 当alert一个空值之后发生了一件怪事。。。。。。
- JAVA的基本问题,很简单
- 一个简单的hibernate 查询
- Quartz调度器直接对方法进行调用,如果方法带参数该在spring中怎么表示
- ◆◆◆◆EJB 与 javaBean 的探讨!!
- 要选.Net还是Java了,大家给点建议。
- 怎样检验一个Java应用程序已经启动
- 请教一个jbuilder + tomcat 问题 StandardHost[localhost]: MAPPING configuration error for request URI /index.jsp
- 如何使用struts的bean:write写出多行内容啊?
- 如何绘制一个曲线图显示在jsp页面。
- 求解决
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() ));
}
}
size = values.substring(0,values.indexOf("Select")+6);
color = values.substring(values.indexOf("Color:"));
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
写个小函数
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];