如何分割以下字符串如何分割以下字符串“LLSlotBook17-07-2015 @ Friday @ 1 @ 10.00AM-12.00PM @ 10 @ LMV,mCWG”with','和'@'
答案 0 :(得分:2)
您可以使用 String.split(regexp)功能:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int color = Color.TRANSPARENT;
Drawable background = parent.getChildAt(position).getBackground();
if (background instanceof ColorDrawable)
color = ((ColorDrawable) background).getColor();
if(color == Color.CYAN)
{ parent.getChildAt(position).setBackgroundColor(Color.TRANSPARENT);}
else {
parent.getChildAt(position).setBackgroundColor(Color.CYAN);
TextView t;
t = (TextView) view.findViewById(R.id.file_path);
files_selected.addElement(t.getText().toString());
}
}
}
答案 1 :(得分:0)
你应该更喜欢VLef提到的String.split方法, 但为了完整起见:
String s = "LLSlotBook17-07-2015@Friday@1@10.00AM-12.00PM@10@LMV,mCWG";
int x = s.indexOf("@");
String sub = s.substring(0, x);
将为您提供第一个子字符串“LLSlotBook17-07-2015”。
请参阅:http://docs.oracle.com/javase/7/docs/api/java/lang/String.html