【发布时间】:2014-01-26 03:25:42
【问题描述】:
我从数据库中检索到的字符串包含我需要删除的 \。但是当我放置 replaceAll 函数时,它标记了一个错误。有人帮忙吗???
String I retrieved: Bebo\'b
String required: Bebo'b
我试过这个函数:str.replaceAll("\",""); 标记一个错误,其中 str 是检索到的字符串。
【问题讨论】:
我从数据库中检索到的字符串包含我需要删除的 \。但是当我放置 replaceAll 函数时,它标记了一个错误。有人帮忙吗???
String I retrieved: Bebo\'b
String required: Bebo'b
我试过这个函数:str.replaceAll("\",""); 标记一个错误,其中 str 是检索到的字符串。
【问题讨论】:
使用函数str.replaceAll("\\'","'");
【讨论】:
PatternSyntaxException
试试这个..
str.replaceAll("\\","");
或者
str.replaceAll(Pattern.quote("\\'"), "'")
【讨论】:
试试这个:
String result=str.replaceAll("\'\'", "");
虽然"\" 被视为转义序列字符,所以它是单个"\" 是行不通的。
【讨论】:
PatternSyntaxException
您应该尝试.replace("\", "") 功能。否则,您可以尝试 str.replaceAll("\'\", ""); 使用 '\' 作为转义序列。
【讨论】:
PatternSyntaxException。
public class XYZ {
public static void main(String argss[]) {
String p="123\' 5677fg\' ffd";
System.out.println(p.replaceAll("/", "")); }
}
试试这个
【讨论】:
/
String str = "Bebo\\'b";
str.replaceAll("\\","");
System.out.println(str);
【讨论】:
使用此代码。
String ss="Bebo\'b"; 字符串 aa=ss.replaceAll("'\'",""); tv.setText(aa);
【讨论】:
【讨论】: