2014-10-22 88 views
0

我有下面的字符串,我成功地通過引號逃脫引號。在Java中的字符串中逃脫引號

 <Test sample=\"5\" couponCode=\"\"><WeatherApp>" 
     + "<Temp><UpdateInfo><WeatherDetail>" 
     + "<Release batchNo=\"\"/>" 
     + "</WeatherDetail></UpdateInfo></Temp>"  
     + "</WeatherApp></Test> 

我的問題是,可以說我想要替換的一個值在此字符串與我DTO.getVal(),我該怎麼辦呢?

對於如 -

 <Test sample="dto.getVal()" couponCode=\"\"><WeatherApp>" 
     + "<Temp><UpdateInfo><WeatherDetail>" 
     + "<Release batchNo=\"\"/>" 
     + "</WeatherDetail></UpdateInfo></Temp>"  
     + "</WeatherApp></Test> 

我已經這樣做了多種方式,並且都沒有成功爲止。你能給些建議麼?

+0

使用+連接字符串的變量。 – zerologiko 2014-10-22 08:08:39

+0

這樣做:sample =「+ dto.getVal()+」coupon – 2014-10-22 08:09:37

+0

「 – BarrySW19 2014-10-22 08:10:22

回答

2
<Test sample=\""+dto.getVal()+"\" couponCode=\"\"><WeatherApp>" 
     + "<Temp><UpdateInfo><WeatherDetail>" 
     + "<Release batchNo=\"\"/>" 
     + "</WeatherDetail></UpdateInfo></Temp>"  
     + "</WeatherApp></Test> 
+0

是的,您。 – rickygrimes 2014-10-22 08:18:54

0

只需使用字符串連接:\"" + dto.getVal() + "\"