日期:2014-05-20  浏览次数:20706 次

急,在线 java 中怎样把 ' 换为 \'
原始字符串:
FUN FILMS FOR SUMMER-(3-1-A)-You'll smile
通过 String replace方法,把 ' 换为 \'

处理过就该是这样的:
FUN FILMS FOR SUMMER-(3-1-A)-You\'ll smile

------解决方案--------------------
str.replace(“’”,"\\\'")试试看
------解决方案--------------------
Java code
public class Test {
    public static void main(String[] args) {
        String str  = "FUN FILMS FOR SUMMER-(3-1-A)-You'll smile" ;
        System.out.println("原始:" + str) ;
        System.out.println("结果:" + str.replace("'","\\'")) ;
        }
}