Replace all escape sequences with non escape equivalent strings in Java
•
Java
I have a string like this:
<![CDATA[<ClinicalDocument>rest of CCD here</ClinicalDocument>]]>
I want to replace the escape sequence with their non escape characters, and finally get:
<![CDATA[<ClinicalDocument>rest of CCD here</ClinicalDocument>]]>
Solution
This is a non - regular expression solution
String original = "something"; String[] escapes = new String[]{"<",">"}; // add more if you need String[] replace = new String[]{"<",">"}; // add more if you need String new = original; for (int i = 0; i < escapes.length; i++) { new = new.replaceAll(escapes[i],replace[i]); }
Sometimes simple loops are easier to read, understand, and code
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码