Here you can find the source of forHTML(final String aText)
Parameter | Description |
---|---|
aText | string. |
public static String forHTML(final String aText)
//package com.java2s; //License from project: Open Source License import java.text.CharacterIterator; import java.text.StringCharacterIterator; public class Main { /**// w w w. j a va 2s . co m * Encodes the string to be used in HTML. * * @param aText string. * @return encoded. */ public static String forHTML(final String aText) { final StringBuilder result = new StringBuilder(); final StringCharacterIterator iterator = new StringCharacterIterator(aText); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '\"') { result.append("DOUBLE_QUOTE"); } else if (character == '\r') { result.append("RETURN_CAR"); } else if (character == '\n') { result.append("NEW_LINE"); } else if (character == '\'') { result.append("SINGLE_QUOTE"); } else { // the char is not a special one // add it to the result as is result.append(character); } character = iterator.next(); } return result.toString(); } }