好吧,我想打电话给
String newString = oldString.replaceAll("}","");
但是我尝试过的 } 出现错误:
String newString = oldString.replaceAll("\\}\\","");
String newString = oldString.replaceAll("\}\","");
String newString = oldString.replaceAll("//}//","");
String newString = oldString.replaceAll("/}/","");
而且它们都不起作用。我怎么能那样做?
谢谢
这是错误:
10-19 12:17:44.907: W/System.err(7030): java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1:
10-19 12:17:44.907: W/System.err(7030): }
10-19 12:17:44.907: W/System.err(7030): ^
10-19 12:17:44.907: W/System.err(7030): at java.util.regex.Pattern.compileImpl(Native Method)
10-19 12:17:44.907: W/System.err(7030): at java.util.regex.Pattern.compile(Pattern.java:400)
10-19 12:17:44.907: W/System.err(7030): at java.util.regex.Pattern.<init>(Pattern.java:383)
10-19 12:17:44.907: W/System.err(7030): at java.util.regex.Pattern.compile(Pattern.java:374)
10-19 12:17:44.907: W/System.err(7030): at java.lang.String.replaceAll(String.java:1784)
10-19 12:17:44.907: W/System.err(7030): at com.rotaryheart.MainActivity$1.onClick(MainActivity.java:70)
10-19 12:17:44.907: W/System.err(7030): at android.view.View.performClick(View.java:4084)
10-19 12:17:44.907: W/System.err(7030): at android.view.View$PerformClick.run(View.java:16966)
10-19 12:17:44.907: W/System.err(7030): at android.os.Handler.handleCallback(Handler.java:615)
10-19 12:17:44.907: W/System.err(7030): at android.os.Handler.dispatchMessage(Handler.java:92)
10-19 12:17:44.907: W/System.err(7030): at android.os.Looper.loop(Looper.java:137)
10-19 12:17:44.907: W/System.err(7030): at android.app.ActivityThread.main(ActivityThread.java:4940)
10-19 12:17:44.907: W/System.err(7030): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 12:17:44.907: W/System.err(7030): at java.lang.reflect.Method.invoke(Method.java:511)
10-19 12:17:44.915: W/System.err(7030): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
10-19 12:17:44.915: W/System.err(7030): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
10-19 12:17:44.915: W/System.err(7030): at dalvik.system.NativeStart.main(Native Method)
这是 MainActivity.java 70 行
String newString = oldString.replaceAll("}","");
好吧,这是我的 onClick 电话
go.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
try {
oldString= "} test } for }";
Toast.makeText(getApplicationContext(), "Test for }",
Toast.LENGTH_SHORT).show();
String newString = oldString.replaceAll("}", "");
Toast.makeText(getApplicationContext(), ""+newString , Toast.LENGTH_LONG).show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});