日期:2014-05-20 浏览次数:20892 次
public class C {
public static void operate(String str){
while(str.indexOf("[") >= 0)
str = str.substring(0, str.indexOf("[")).concat(str.substring(str.indexOf("]")+1,str.length()));
System.out.println(str);
}
/**
* @param args
*/
public static void main(String[] args) {
C.operate("[同作者作品]o'reilly[同译者作品][同作者作品] taiwan公司[同作者作品]");
}
}
------解决方案--------------------
str.replaceAll("[同译者作品]","");
str.replaceAll("[同作者作品]","");
------解决方案--------------------
String str = "o'reilly[同译者作品][同作者作品] taiwan公司";
int c = 0;
for (int i = 0; i < str.length(); i++) {
if ("[".equals([color=#FF0000]new Character(str.charAt(i)).toString()[/color])) {
c++;
}
}
System.out.println(c);
for (int j = 0; j < c; j++) {
str = str.substring(0, str.indexOf("[")).concat(
str.substring(str.indexOf("]") + 1, str.length()));
}
System.out.println(str);