(Java) HTML Entity Encode and Decode in StringBuilder
Demonstrates HTML encoding and decoding the contents of a StringBuilder. Note: This example requires Chilkat v11.1.0 or greater.
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
CkStringBuilder sb = new CkStringBuilder();
String s = "< é ü ç Ω Hello & World ✓ >";
sb.Append(s);
sb.Encode("html","utf-8");
System.out.println(sb.getAsString());
// Output:
// < é ü ç Ω Hello & World ✓ >
// To decode:
sb.Decode("html","utf-8");
System.out.println(sb.getAsString());
// Output:
// < é ü ç Ω Hello & World ✓ >
}
}
|