简体   繁体   中英

Escape quotes in a String in Java

I have the below string in which I am successfully escaping the quotes with .

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

My question is, lets say I want to replace one of the values in this string with my DTO.getVal(), how do I do it?

For eg -

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

I have done this multiple ways, and haven't been successful so far. Can you please advise?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM