Unquote a StringTag(s): String/Number
We use the fact that the Properties unquote a String, so we simply simulate a Property read with our String.
Maybe not the best way but it is certainly very easy!
import java.io.*;
import java.util.*;
public class Unquote {
public static void main(String[] args) {
String a = "Visit Real\\'s at http://www.rgagnon.com";
System.out.println(a);
String b = unquote(a);
System.out.println(b);
/*
output :
Visit Real\'s at http://www.rgagnon.com
Visit Real's at http://www.rgagnon.com
*/
}
public static String unquote(String a) {
Properties prop = new Properties();
try {
prop.load(new ByteArrayInputStream(("x=" + a).getBytes()));
}
catch (IOException ignore) {}
return prop.getProperty("x");
}
}
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com