67,513
社区成员
发帖
与我相关
我的任务
分享
String str = "张三2";
str = str.replace("*", ""); //去掉*
str = str.replace("2", ""); //去掉2
//下面是截去"("后面的部分
int index = str.indexOf("(");
if (index > 0){
str = str.substring(0, str.indexOf("("));
}
"李四(教)".substring(0, "李四(教)".indexOf("("));//返回"李四",这里只是使用String类提供的api方法简单的解决
public static void main(String args[])
{
String s = "张三* 李四(教) 王二五(检) 欧阳乌龟(教)";
String s1[] = s.split(" ");
for (String str : s1)
{
if (str.length() > 0)
{
str = str.replace("*", "");
int index = str.indexOf("(");
if (index > 0)
{
str = str.substring(0, str.indexOf("("));
}
System.out.println(str);
}
}
}