Here you can find the source of htmlEncode(String s)
Parameter | Description |
---|---|
s | string to encode |
public static String htmlEncode(String s)
//package com.java2s; /*// w ww . j ava 2 s. c o m * Copyright 2009 Yodlee, Inc. All Rights Reserved. Your use of this code * requires a license from Yodlee. Any such license to this code is * restricted to evaluation/illustrative purposes only. It is not intended * for use in a production environment, and Yodlee disclaims all warranties * and/or support obligations concerning this code, regardless of the terms * of any other agreements between Yodlee and you." */ public class Main { /** * Helper method to html encode a string. Used for dumping the form * output. * * @param s string to encode * @return encoded version */ public static String htmlEncode(String s) { StringBuffer sb = new StringBuffer(); int n = s.length(); for (int i = 0; i < n; i++) { char c = s.charAt(i); switch (c) { case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; case '"': sb.append("""); break; default: sb.append(c); break; } } return sb.toString(); } }