3

示例代码

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
4

2 回答 2

24

您正在检查 2"(double quotes)s而您的字符串开头只有一个。试试下面:

 test.startsWith("\"");
 test.endsWith("\"");

应该管用。

于 2012-10-07T05:40:28.473 回答
0

我不完全确定您想要实现什么,但请确保在对其执行任何操作之前初始化“测试”。

您只需要检查“test”是否以单个双引号开头,因为第一个双引号不是字符串内容的一部分。

于 2012-10-07T05:44:36.370 回答