【发布时间】:2012-09-27 19:09:42
【问题描述】:
示例代码
public static void main(String args[]){
String test=null;
if(some condition)
test = "\"abc\"";
else
test ="def";
// if condition is true , in debug mode when i check the value of test its ""abc"" (double double quote);
// if condition is false , then value of test is "def" (double quotes only one time);
}
寻找一个逻辑来检查字符串是否有双双引号。试过下面的东西
// test.startsWith("\"\"")) // this didn;t work
【问题讨论】:
-
if(test.startsWith("\"\"")){ System.out.println("has double double qoutes"); }为我工作 -
if (test.charAt(0) == 34 && test.charAt(test.length()-1) == 34) { System.out.println("有双引号"); ascii 表中的 34 代表 doublequote ,因此它工作正常。
-
@vandey:谢谢,是的,这行得通